1
votes

I've created a library and installed it in /usr/lib (using cmake) eg.:

set(CMAKE_INSTALL_PREFIX /usr/) 
target_link_libraries(ssd1306)
set_target_properties(ssd1306 PROPERTIES   VERSION 1.0.0   SOVERSION 1 )
install(TARGETS ssd1306 DESTINATION lib)   
install(FILES ${SSD1306_HEADERS} DESTINATION include)

This worked fine and the library is present on my filesystem: The library:

ls -l /usr/lib/libssd1306*

/usr/lib/libssd1306.so -> libssd1306.so.1
/usr/lib/libssd1306.so.1 -> libssd1306.so.1.0.0
/usr/lib/libssd1306.so.1.0.0

And the header:

ls -l /usr/include/ssd1306.h

/usr/include/ssd1306.h

Then I wrote a program which use the library (again using cmake):

target_link_libraries(ssd1306-info libssd1306)

But for some reason it will not link to my library at compile time:

/usr/bin/ld: cannot find -llibssd1306

The header file was found and the object file was created, but linking failed.

Of course /usr/lib/ is in g++ search path:

g++ -print-search-dirs

install: /usr/lib/gcc/x86_64-linux-gnu/5/ programs: =/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/bin/ libraries: =/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/:/lib/x86_64-linux-gnu/5/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/5/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../:/lib/:/usr/lib/

What do I do wrong?

1
Try running make in verbose mode to see how it attempt to build your program. You do it by adding the VERBOSE=1 argument when running make.Some programmer dude
I think you need to update the library cache by running ldconfig.PSkocik
Shouldn't it be only target_link_libraries(ssd1306-info ssd1306)?skypjack
Are you running into 32-bit vs 64-bit library issues?Jonathan Leffler
Have you double checked all these symlinks?Mati

1 Answers

0
votes

Figured it out.

Both the library and the executable where linking in the same object (.o) file.

The 'arduino' stuff was about a external variable which should not be there (copy-and-paste code issue).