I have been trying to compile a trivial static library.
I used the library in another project
This is my folder structure:
GppCompile >
bin >
//The executable should be compiled here
deps >
libLog.a //The static library
inc >
log.h //header for the functions
main.cpp
The libLog.a is made from log.o
The log.cpp source file contains a Logger class function printRaw in the namespace Log
The log.h contains the class prototype and it is also in the namespace Log
main.cpp
#include <iostream>
#include "log.h"
int main(){
Log::Logger l;
l.printRaw("Hello I am doing C++ programming");
}
I compiled main.cpp using the following command:
g++ -Iinc -Ldeps -lLog -o bin/main.exe main.cpp
It showed me:
main.cpp:(.text+0x23): undefined reference to `Log::Logger::printRaw(char const*)'
collect2.exe: error: ld returned 1 exit status
I tried using -I/inc -L/deps -lLog.a, changing names, but to no avail. I don't understand, my function is already defined in libLog.a, why the compiler cannot recognize it?
Thanks.
Oh...
But if no slashes means relative path, why the command I originally typed is not working?
Sorry, the spaces had stripped away, this is the folder structure..
GppCompile>>
-------------deps>>
---------------------libLog.a
-------------bin>>
-------------inc>>
--------------------log.h
------------main.cpp
I was compiling in the GppCompile directory. Is that my relative path of -Iinc -Ldeps means GppCompile/inc and GppCompile/deps?