// 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;
}
int SampleAddInt(int, int);
void SampleFunction1();
int SampleFunction2();
#include <iostream>
#include <imageloader.h>
using namespace std;
int main()
{
cout << SampleAddInt(1, 4) << endl;
return 0;
}
Logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
-------------- 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
mingw32-g++.exe -LE:\Packs\SLtest\lib -o bin\Debug\test.exe obj\Debug\main.o -limageloader -lmingw32...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.
SLtest is the dir the library is located in.
I've re-done this several times, keep getting the same error, what if you guys do these steps, do you get the same error too?I have done it similar and it just works. I have attached a sample workspace for your convenience. Probably this will help you to get where you want. I does not have a header file... this content is directly inside the main application (I was too lazy to do the header file...)
how could that ever work? How could it know the functions if the library isn't compiled, and how can it find these lib files?Trust me: the library *is* compiled. :D
I used a project dependency herePart of the confusion may result from your lib_usage.zip file. The included lib_usage.workspace file does not include the dependency relation. Perhaps when you closed and zipped the project files, you may have forgotten to explicitly save the workspace file. The dependency, which is stored in the workspace file, was therefore lost.