User forums > General (but related to Code::Blocks)
static library [SOLVED]
sspecter:
Its not working.
Im trying 2 things:
- creating the lib .a without header. The program give an error then i try to use it, as if i didnt declared it.
- creating the lib .a with header. The i try to compile the lib, it give the following error:
mingw32-g++.exe -I"D:\Arquivos de programas\CodeBlocks\include" -c lib\ssptoolslib.cpp -o lib\ssptoolslib.o
mingw32-g++.exe -L"D:\Arquivos de programas\CodeBlocks\lib" -o lib\ssptoolslib.exe lib\ssptoolslib.o -lmingw32
lib\ssptoolslib.o:ssptoolslib.cpp:(.text+0x12db): undefined reference to `tools::showMessage(std::string)'
lib\ssptoolslib.o:ssptoolslib.cpp:(.text+0x138a): undefined reference to `tools::showMessage(std::string)'
D:\Arquivos de programas\CodeBlocks\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
As you can see the lib im trying to create now is not the above as i said before. If you want i can post the code.
is there any tutorial for newbies about creating static libs?
btw: must i create a header for the .a lib or there is no necessity in it?
MortenMacFly:
--- Quote from: sspecter on February 27, 2006, 01:21:25 pm ---mingw32-g++.exe -L"D:\Arquivos de programas\CodeBlocks\lib" -o lib\ssptoolslib.exe lib\ssptoolslib.o -lmingw32
--- End quote ---
You are trying to make an EXE file out of a lib. I guess that your type of project is wrong. Make sure if you start a new project you select "Static Library" as project type.
With regards, Morten.
thomas:
--- Quote ---must i create a header for the .a lib or there is no necessity in it?
--- End quote ---
Not if you declare the functions in the program that links to it. Otherwise, you certainly have to... the compiler won't otherwise know what to do.
--- Quote ---is there any tutorial for newbies about creating static libs?
--- End quote ---
About 566.000...
http://www.google.com/search?q=c%2B%2B+static+libraries+tutorial
sspecter:
--- Quote ---You are trying to make an EXE file out of a lib. I guess that your type of project is wrong. Make sure if you start a new project you select "Static Library" as project type.
With regards, Morten.
--- End quote ---
Youre right. the lib with a header that i was creating was in a wrong project. Now i can create the lib without error
But i still cant use it. I get undefined reference then i try to use it.
I know the project is finding the header, because it compile. and i know it is finding the library, because it dont get "cant find -llibssptools.a". But I get undefined reference errors, even when im defining the references in the lib.
the problem appears to be inside the library.
But actually im trying to use Newton library and im getting the same error. So it can be some C::B configuration. But i am already using Ogre and CeGUI libs without error in C::B. So... im clueless.
for people wanting to se the code here are parts of it:
http://pastebin.com/575053
MortenMacFly:
--- Quote from: sspecter on February 27, 2006, 05:25:34 pm ---http://pastebin.com/575053
--- End quote ---
...if I remove the namespace "tools" completely it works fine. Maybe this helps...?!
Morten.
Edit: Here is my main then:
--- Code: ---#include <iostream>
#include "ssptools.h"
using namespace std;
//using namespace tools;
int main()
{
showMessage("Hello world!\n");
Point3D p(1,2,3);
return 0;
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version