User forums > Using Code::Blocks
How to build a static lib ?
leeya:
I create a project of static lib, and write a basic win32 app. I want to static lib.
The project structure is following:
│ RSWL2GCC.cbp
│
├─Win
│ WinMain.h
│ WinMain.cpp
│
└─obj
└─Debug
└─Win
WinMain.h is defined:
#ifndef WINMAIN_H
#define WINMAIN_H
#include <windows.h>
namespace Win
{
int Main (INSTANCE inst, char const * cmdParam, int cmdShow);
}
#endif // WINMAIN_H
WinMain.cpp is defined:
#include <windows.h>
#include <Win/WinMain.h>
int WINAPI WinMain
(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdParam, int cmdShow)
{
return Win::Main (hInst, cmdParam, cmdShow);
}
I build the project , get error message :
:: === RSWL2GCC, Debug ===
D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp:2: Win/WinMain.h: No such file or directory
D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp:7: error: `Win' has not been declared
D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp:7: error: `Main' was not declared in this scope
D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp:7: warning: unused variable 'Main'
:: === Build finished: 3 errors, 1 warnings ===
Why I failed ?
SamT:
D:\CodeWorld\RSWL2GCC\Win\WinMain.cpp:2: Win/WinMain.h: No such file or directory
GCC can't find your WinMain.h. Have you try to add some path information into Project->Build Options->Search Directories->Compiler ?
leeya:
:D
You are the best!
Thank You!
I add the search path to project, all is right; I has generated "libRSWL2GCC.a" file successfully.
I have another problem, how to specify the name and path of the generated static lib file name in C::B ?
for instance, i want the .a file under "%working directroy%/lib" and named "RSWL2GCCD.a".
TDragon:
--- Quote from: leeya on April 12, 2007, 05:19:49 pm ---I have another problem, how to specify the name and path of the generated static lib file name in C::B ?
--- End quote ---
In the "Build targets" section of the project options (select Properties from the Project menu or the project's right-click context menu), see "Output filename".
--- Quote ---for instance, i want the .a file under "%working directroy%/lib" and named "RSWL2GCCD.a".
--- End quote ---
GCC and MinGW encourage developers to prefix import libraries with "lib", and I think this is a good thing. Code::Blocks will do this for you automatically, but if you really want to you can disable this by unchecking the "Auto-generate filename prefix" box.
leeya:
Thanks~~
I have find the configuration of static lib;
I create a new project called "UnitTest", the Main.cpp file defined as following:
#include <Win/WinMain.h>
int Win::Main (HINSTANCE hInst, char const * cmdParam, int cmdShow)
{
return 0;
}
I want libRSWL2GCC.a to compile with project "UnitTest", so could run a basic win32 application.
how can i add libRSWL2GCC.a to my "UnitTest" project?
My file compositon structure was as following:
D:\CODEWORLD\RSWL2GCC
│ WinLibBase.h
│ RSWL2GCC.depend
│ libRSWL2GCC.a
│ RSWL2GCC.cbp
│ RSWL2GCC.layout
│
├─Win
│ WinMain.cpp
│ WinMain.h
│
├─obj
│ └─Debug
│ └─Win
│ WinMain.o
│
└─UnitTest
│ UnitTest.cbp
│ UnitTest.layout
│ UnitTest.depend
│ Main.cpp
│
├─obj
│ └─Debug
│ Main.o
│
└─bin
└─Debug
I configure complier search path to "D:\CODEWORLD\RSWL2GCC",so that compiler find the file;
Build project and get error message:
C:\MinGW\lib\libmingw32.a(main.o):main.c:(.text+0x106):: undefined reference to `WinMain@16'
:: === Build finished: 1 errors, 0 warnings ===
It obviously show that "UnitTest" could not find the program entry point; but i have defined that in libRSWL2GCC.a;
why i failed ?
Navigation
[0] Message Index
[#] Next page
Go to full version