Community
Participate
Working Groups
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.
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.
(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.
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.
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.
Fixed in 8.0.1 and master > 20110725.
*** 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
*** 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
*** Bug 353786 has been marked as a duplicate of this bug. ***