User forums > Using Code::Blocks

How to build a static lib ?

<< < (2/5) > >>

TDragon:
Is "RSWL2GCC" in your link libraries? Post your build log after enabling full command line logging (Settings->Compiler and debugger->Global compiler settings->Other settings->Compiler logging).

leeya:

--- Quote from: TDragon on April 14, 2007, 12:00:08 am ---Is "RSWL2GCC" in your link libraries? Post your build log after enabling full command line logging (Settings->Compiler and debugger->Global compiler settings->Other settings->Compiler logging).

--- End quote ---

I enabled the build log by your instruction, I build the RSWL2GCC again, get informtion as following:

-------------- Build: Debug in RSWL2GCC ---------------
mingw32-g++.exe -Wall -g  -ID:\CodeWorld\RSWL2GCC\ -ID:\CodeWorld\RSWL2GCC\Win -IC:\MinGW\include  -c D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp -o obj\Debug\Win\WinMain.o
ar.exe -r -s libRSWL2GCC.a obj\Debug\Win\WinMain.o
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings

where can i add libRSWL2GCC.a into my UnitTest project ?

I build UnitTest project , the build log show :

-------------- Build: Debug in UnitTest ---------------
mingw32-g++.exe -Wall -g  -ID:\CodeWorld\RSWL2GCC -IC:\MinGW\include  -c D:\CodeWorld\RSWL2GCC\UnitTest\Main.cpp -o obj\Debug\Main.o
mingw32-g++.exe -LC:\MinGW\lib  -o bin\Debug\UnitTest.exe obj\Debug\Main.o   
C:\MinGW\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings

SamT:
undefined reference to `WinMain@16'

the winmain is designed by yourself, you need to link the library when you want to generate exectuive file.

There are two ways to add library in a project.
1. Add path information where can find the library in Project->Build Options->Search Directories->linker
Then add the library name in Project->Build Options->Linker settings->add link libraries

2. set full path, library name directly in Project->Build Options->Linker settings->add link libraries

Benfit of method 1: you can set the path information with "global variable", ex: there is a global variable "wx" = C:\wxWidgets-2.8.3, you can put your path information with $(#wx)/include, $(#wx)/lib... Just need to change the value of wx, you change everything.
Benfit of method 2: easy to use. You can know which library you link exactly since all the path and libary name are put together.

It's your choose to include the link library. Thanks C::B for it's flexibility.

leeya:
Thanks for your detail instruction!


--- Quote from: SamT on April 14, 2007, 04:41:02 am ---2. set full path, library name directly in Project->Build Options->Linker settings->add link libraries

--- End quote ---

I add the libRSWL2GCC.a lib in my project according to your way 2, but after building the project again, i get trapped :

-------------- Build: Debug in UnitTest ---------------
mingw32-g++.exe -LC:\MinGW\lib  -o bin\Debug\UnitTest.exe obj\Debug\Main.o    D:\CodeWorld\RSWL2GCC\libRSWL2GCC.a
C:\MinGW\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
1 errors, 0 warnings

Libarary libRSWL2GCC.a  file was found in building process, however, the error message are still the same.
Why? :(

In libRSWL2GCC.a file, the WinMain,the program entry point, was defined.

TDragon:
A Google search for "mingw WinMain in static library" turned up this post, which has the following to say:

--- Quote ---To resolve _WinMain@16 with a symbol from your library, it needs to come *after* the library that needs it (/usr/i686-pc-mingw32/lib/libmingw32.a). Unfortunately (for you), gcc/g++ puts all the default libraries *last* when it calls ld.  You need to override that order.

--- End quote ---

Since the default library in question is libmingw32.a, all we need to do is make sure it's linked before your library containing the WinMain. The easiest way to do this is add it to your project's Link libraries, before your RSWL2GCC library. Just add "mingw32" and move it above RSWL2GCC, and it should work.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version