Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344009 - Eclipse CDT uses wrong command to build static library
Summary: Eclipse CDT uses wrong command to build static library
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 8.0.1   Edit
Assignee: Marc-André Laperle CLA
QA Contact: Andrew Gvozdev CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-27 13:40 EDT by Vimal CLA
Modified: 2011-08-03 13:16 EDT (History)
5 users (show)

See Also:


Attachments
Add static lib tool to crossgcc and msvc (4.07 KB, patch)
2011-07-26 01:03 EDT, Marc-André Laperle CLA
malaperle: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vimal CLA 2011-04-27 13:40:30 EDT
Build Identifier: M20100909-0800

If I select an option to build static library using ecilpse CDT, it compiles the files correctly but while linking uses "g++ -o" instead of "ar -rcs" command which I think should be the command to build a static library. The build fails therefore since it tries to find "main" function which may not be present in a static library.

Reproducible: Always

Steps to Reproduce:
1. Go to File-> New -> C++Project -> Static Library -> Empty Project
2. Give a clean build using Project -> clean
3. In the console windown at the end of the build you will find the "g++ -o" invoked.
Comment 1 Andrew Gvozdev CLA 2011-04-27 14:00:53 EDT
Which toolchain are you using? Here is what I am getting:

**** Build of configuration Debug for project StaticLib ****

**** Internal Builder is used for build               ****
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o src\hello.o ..\src\hello.c
ar -r libStaticLib.a src\hello.o
ar: creating libStaticLib.a
Build complete for project StaticLib
Time consumed: 156  ms.
Comment 2 Vimal CLA 2011-04-27 15:48:16 EDT
(In reply to comment #1)
> Which toolchain are you using? Here is what I am getting:
> **** Build of configuration Debug for project StaticLib ****
> **** Internal Builder is used for build               ****
> gcc -O0 -g3 -Wall -c -fmessage-length=0 -o src\hello.o ..\src\hello.c
> ar -r libStaticLib.a src\hello.o
> ar: creating libStaticLib.a
> Build complete for project StaticLib
> Time consumed: 156  ms.

Cross GCC is the toolchain.
I am using MinGW for the compiler.
I tried again and this time a c project ( earlier it was c++ project ) but the result was the same. 
Here is the output
**** Build of configuration Debug for project Test ****

make all 
'Building file: ../src/hello.c'
'Invoking: Cross GCC Compiler'
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hello.d" -MT"src/hello.d" -o"src/hello.o" "../src/hello.c"
'Finished building: ../src/hello.c'
' '
'Building target: Test.a'
'Invoking: Cross GCC Linker'
gcc  -o"Test.a"  ./src/hello.o   
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
make: *** [Test.a] Error 1

The fact is when I create a C++ or C project and select a static library option then upon checking at "Properties -> C/C++ build -> Settings -> Tool Settings -> Cross GCC Linker -> Command" the command shown is gcc ( or g++ for c++ ) whereas it should be ar -rcs. If I manually change the command and re run the build it works just fine.
Comment 3 Alexander Stante CLA 2011-07-20 09:24:14 EDT
Version: 8.0.0.201106081058
Build id: 201106081058

I can confirm the same issues with the Microsoft Visual C++ builder. When selecting to build a static library the linker (link) is invoked instead of the Library Manager (lib). In the C/C++ Build settings the library manager is correctly configured. As a workaround I just exchanged the linker command "link" with "lib" because I haven't found any other way to tell the builder not to link but call the Library Manager.
Comment 4 Marc-André Laperle CLA 2011-07-26 01:03:16 EDT
Created attachment 200327 [details]
Add static lib tool to crossgcc and msvc

This patch adds the two missing tools and enables/disables them when appropriate, like the GCC toolchains do.
Comment 5 Marc-André Laperle CLA 2011-07-26 01:05:57 EDT
Fixed in 8.0.1 and master > 20110725.
Comment 6 CDT Genie CLA 2011-07-26 01:18:39 EDT
*** cdt git genie on behalf of 344009 ***

    Bug 344009 - Eclipse CDT uses wrong command to build static library
    (crossgcc, msvc)

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c7f03bd3d99986215778bbac8b3b081ed2a6ae03
Comment 7 CDT Genie CLA 2011-07-26 01:18:41 EDT
*** cdt git genie on behalf of 344009 ***

    Bug 344009 - Eclipse CDT uses wrong command to build static library
    (crossgcc, msvc)

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=510afbddc7e464d2608aa69f9d75b4ce03e8777e
Comment 8 Marc-André Laperle CLA 2011-08-03 13:16:43 EDT
*** Bug 353786 has been marked as a duplicate of this bug. ***