简体   繁体   中英

Cannot import shared library with g++

i made a shared library, linked it to a main program, but this main program cannot see any of the shared library methods, nor import it's headers. This is what i did:

  1. I compiled each cpp file of the library in position independent code
 g++ -c -fPIC -o objname.o objname.cpp -I"HeadersFolder" 
  1. I created the shader library, and it is correctly created with the right name in my main directory
 g++ -shared -o libmylib.so obj1.o obj2.o etc.. etc.. 
  1. I'm trying to compile a simple main with:
 g++ main.cpp -L. -lmylib 

Now in this main i imported one of the lib headers, something like:

#include <Header.hpp>

And g++ tells me no such file or directory.

"Now in this main i imported one of the lib headers, something like: ..."

You also need to add the -I option to compile main.cpp in this case:

g++ main.cpp -I"HeadersFolder" -L. -lmylib

Also you should use

#include "Header.hpp" // Note the quotes "

the angle brackets ( <> ) are for including system headers (that could possibly collide with your own when the preprocessor evaluates them).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM