User forums > Using Code::Blocks
Linking error
Decrius:
Hi,
I have 2 projects, a static library and a console application.
This is the code of the library:
imageloader.cpp
--- Code: ---// The functions contained in this file are pretty dummy
// and are included only as a placeholder. Nevertheless,
// they *will* get included in the static library if you
// don't remove them :)
//
// Obviously, you 'll have to write yourself the super-duper
// functions to include in the resulting library...
// Also, it's not necessary to write every function in this file.
// Feel free to add more files in this project. They will be
// included in the resulting library.
// A function adding two integers and returning the result
int SampleAddInt(int i1, int i2)
{
return i1 + i2;
}
// A function doing nothing ;)
void SampleFunction1()
{
// insert code here
}
// A function always returning zero
int SampleFunction2()
{
// insert code here
return 0;
}
--- End code ---
imageloader.h
--- Code: ---int SampleAddInt(int, int);
void SampleFunction1();
int SampleFunction2();
--- End code ---
Sources of the console application:
main.cpp
--- Code: ---#include <iostream>
#include <imageloader.h>
using namespace std;
int main()
{
cout << SampleAddInt(1, 4) << endl;
return 0;
}
--- End code ---
I build the library, put it in a search directory and linked to it.
Error:
E:/C/test/main.cpp:8: undefined reference to `SampleAddInt(int, int)'
What could possibly be wrong?
Thanks,
Decrius
Ceniza:
Please enable full command line logging following Bloody Cake's signature and paste the output of the Build log here.
--- Quote from: Bloody Cake's signature ---Logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
--- End quote ---
Decrius:
--- Quote ----------------- Build: Debug in test ---------------
mingw32-g++.exe -Wall -fexceptions -g -IE:\Packs\SLtest\include -c E:\C\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LE:\Packs\SLtest\lib -o bin\Debug\test.exe obj\Debug\main.o -limageloader -lmingw32
obj\Debug\main.o: In function `main':
E:/C/test/main.cpp:8: undefined reference to `SampleAddInt(int, int)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
--- End quote ---
SLtest is the dir the library is located in.
MortenMacFly:
--- Quote from: Decrius on April 13, 2008, 05:37:26 pm ---mingw32-g++.exe -LE:\Packs\SLtest\lib -o bin\Debug\test.exe obj\Debug\main.o -limageloader -lmingw32
--- End quote ---
...and where in this line do you link against the lib that contains the function?! Is it called "imageloader"?! Otherwise you should add the lib to the linker options in case you missed that. The linker can't know what libs to link against. You are responsible for telling him using the linker options of your target/project.
Your's sincerely, the Bloody Cake.
Deschamps:
--- Quote from: Decrius ---SLtest is the dir the library is located in.
--- End quote ---
The linker is looking for this library in 'E:\Packs\SLtest\lib', not in 'E:\Packs\SLtest'. Maybe, you've copied the library into the wrong folder.
Regards.
Navigation
[0] Message Index
[#] Next page
Go to full version