6

I have a library called mylib.a in the path /home/test/libs/.

How can I add it to the project??

find_library(IDA_LIB NAMES "mylib.a" PATHS "/home/test/libs" NO_DEFAULT_PATH) 

Since it does not have the prefix lib cmake does not find it. If I change the library name to libmylib.a if finds it fine.

2
  • 2
    You note add_library in the title, but the problem is with find_library(). Commented Sep 26, 2016 at 9:00
  • Related: stackoverflow.com/questions/39687754/… (also problem with library's prefix). Commented Sep 26, 2016 at 9:02

2 Answers 2

2

Use following command with absolute file path of your library

target_link_libraries(IDA_LIB /home/test/libs/mylib.a) 
Sign up to request clarification or add additional context in comments.

3 Comments

That doesn't work. I've already tried it. The parameter passed to the linker is -lmylib.a and still tries to find libmylib.a
@user1618465 try providing full path
This doesn't work also when using a variable created by find_library.
0

Try this:

add_library(mylib STATIC IMPORTED) set_target_properties(mylib PROPERTIES IMPORTED_LOCATION /home/test/mylib.a) 

then you can use "mylib" in:

target_link_libraries(myapp mylib ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.