Link project with inner library
-
wrote on 27 Jan 2023, 08:10 last edited by masa4
I added a code folder to my project with some classes and a library folder. Library folder consist some header files that used in classes and a .so file. It is like that:
codefolder:. ├── Class1.cpp ├── Class1.h ├── Class2.cpp ├── Class2.h └── mylib ├── include │ ├── header1.h │ ├── header2.h │ ├── header3.h │ ├── ... └── lib └── libmylib.so
I added whole
codefolder
to my project, qt creator added all cpp and headers to my project, but .so file added like this in.pro
:DISTFILES += \ codefolder/mylib/lib/libmylib.so
Now I got several error like
undefined reference to XXX class
, XXX is which lays in mylibs library. Now how i can link this library with my project. I tried several thing but didnt work. And why my .so added as distfile, what is it?EDIT:
LIBS += <full_path_to_so> #works LIBS += <relative_path_to_so> #does not work
When I tried with full path it worked in this way. Any way to make it work with relative path?
-
I added a code folder to my project with some classes and a library folder. Library folder consist some header files that used in classes and a .so file. It is like that:
codefolder:. ├── Class1.cpp ├── Class1.h ├── Class2.cpp ├── Class2.h └── mylib ├── include │ ├── header1.h │ ├── header2.h │ ├── header3.h │ ├── ... └── lib └── libmylib.so
I added whole
codefolder
to my project, qt creator added all cpp and headers to my project, but .so file added like this in.pro
:DISTFILES += \ codefolder/mylib/lib/libmylib.so
Now I got several error like
undefined reference to XXX class
, XXX is which lays in mylibs library. Now how i can link this library with my project. I tried several thing but didnt work. And why my .so added as distfile, what is it?EDIT:
LIBS += <full_path_to_so> #works LIBS += <relative_path_to_so> #does not work
When I tried with full path it worked in this way. Any way to make it work with relative path?
@masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt
-
@masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt
-
@masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt
-
@masa4 said in Link project with inner library:
it didnt work
Not a good description of a problem...
-
@masa4 said in Link project with inner library:
it didnt work
Not a good description of a problem...
wrote on 27 Jan 2023, 10:03 last edited by@jsulm Do you know a way to use
LIBS
with relative way? for link u shared with me, I am not sure maybe i did it wrong but the guy asking something different in that link. So I tried usingLIBS
again with full path and it worked. But I need relative path so program will be eligible for building at another computers/another paths too. -
@jsulm Do you know a way to use
LIBS
with relative way? for link u shared with me, I am not sure maybe i did it wrong but the guy asking something different in that link. So I tried usingLIBS
again with full path and it worked. But I need relative path so program will be eligible for building at another computers/another paths too.@masa4 said in Link project with inner library:
LIBS with relative way?
What is the problem? Simply use a relative path like
LIBS += -Lsome_folder -llib_name
-
@masa4 said in Link project with inner library:
LIBS with relative way?
What is the problem? Simply use a relative path like
LIBS += -Lsome_folder -llib_name
-
LIBS += -Lcodefolder/mylib/lib/ -llibmylib #cannot find -llibmylib - no such file or directory LIBS += -Lcodefolder/mylib/lib/ -lmylib #cannot find -lmylib - no such file or directory
Both version gives these errors.
@masa4 So, is there a lib called libmylib.so inside codefolder/mylib/lib?
Why would you put a binary of your lib into your source code tree AND also add the code of the lib to your project? This does not make sense and that's why I suggested to do it properly using subdirs project...
1/9