1

I am developing a C++ project in Ubuntu with kDevelop as the IDE. The project makes use of openssl boost cryptopp libraries. While building the project, I am getting the link error as /usr/bin/ld: cannot find -l/home/anz/openssl-1.0.1j/libssl.a.

As far as I know, -l comes along with the name of library(for e.g., -lcryptopp) and not its path. But why is -l is present here before the path? The specified library do exist in this path.

How can I overcome this problem? Thankyou.

EDIT:

Portion from Cmakelists.txt:

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
find_package( Boost COMPONENTS thread system date_time regex filesystem chrono)
include_directories(${Boost_INCLUDE_DIRS})

find_package (OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})
message("LINKED :" ${OPENSSL_LIBRARIES}) # ALL THE LIBRARIES ARE LISTED HERE CORECTLY
ADD_EXECUTABLE(Abc ${Abc_SRC})
TARGET_LINK_LIBRARIES(Abc ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(Abc ${OPENSSL_LIBRARIES})

target_link_libraries(Abc ${CMAKE_DL_LIBS})  
install(TARGETS Abc RUNTIME DESTINATION ./)

EDIT2: Screenshot added Screenshot of CMake Configuration Window in kDevelop

Jackzz
  • 1,417
  • 4
  • 24
  • 53
  • Show your `CMakeLists.txt` – VP. Jan 28 '15 at 07:57
  • From this "portion" of `CMakeLists.txt` I can't see you specified `-l/home/anz/openssl-1.0.1j/libssl.a`. Also, are you sure you have installed `openssl`? Can you find it by running `locate libssl.a` ? – VP. Jan 28 '15 at 09:43
  • Yes I could locate it. As I told, the path to library is specified in cmake configuration window of kDevelop – Jackzz Jan 28 '15 at 09:45
  • The message command lists all the required openssl libraries. – Jackzz Jan 28 '15 at 09:47

3 Answers3

0

Make sure that the library exists and you add -I"Path to your libcryptopp" to the directories that needs to be included for building , if you need to link the library with -l

eg: g++ -o targetobjects -I"Path to your libcryptopp" -lcryptopp

or else you can give the full path to the libcryptopp eg: g++ -o targetobjects "path to the libcryptopp from the makefile location"

Thiyagarajan
  • 1,271
  • 1
  • 14
  • 19
  • I am making use of cmake in kdevelop and building is done from the IDE itself. – Jackzz Jan 28 '15 at 06:20
  • have you added the include directory with include_directories() eg : include_directories(${Path to your libcryptopp}) target_link_libraries(${EXECUTABLE} ${YOUR cryptopp}) – Thiyagarajan Jan 28 '15 at 06:30
  • Yes.. I have done it and in the cmake configuration of the project all paths are being listed correctly. – Jackzz Jan 28 '15 at 06:31
  • Is that libcryptopp library available in "Path to your libcryptopp" .also if the file exists . check if there is any typo is library name in your cmake file . – Thiyagarajan Jan 28 '15 at 06:34
  • NO. the problem is with libssl library. I have checked each character and nothing is wrong. :( – Jackzz Jan 28 '15 at 06:36
  • I specified the location by browsing it from the configuration window. – Jackzz Jan 28 '15 at 06:37
0

In my practice it is best way to find does your library exist in the system is using locate and ld tools:

  1. Locate to find a library itself on the filesystem:

    locate libssl.a
    

    NOTE that it can show a filesystem nodes of files that DONT exists anymore. Use updatedb before using locate.

  2. ld -lssl --verbose to find library by linker which uses system LD_LIBRARY_PATH variable:

    :~$ ld -lssl --verbose
    attempt to open /usr/x86_64-linux-gnu/lib64/libssl.so failed
    attempt to open /usr/x86_64-linux-gnu/lib64/libssl.a failed
    attempt to open /usr/local/lib/x86_64-linux-gnu/libssl.so failed
    attempt to open /usr/local/lib/x86_64-linux-gnu/libssl.a failed
    attempt to open /usr/local/lib64/libssl.so failed
    attempt to open /usr/local/lib64/libssl.a failed
    attempt to open /lib/x86_64-linux-gnu/libssl.so failed
    attempt to open /lib/x86_64-linux-gnu/libssl.a failed
    attempt to open /lib64/libssl.so failed
    attempt to open /lib64/libssl.a failed
    attempt to open /usr/lib/x86_64-linux-gnu/libssl.so succeeded
    -lssl (/usr/lib/x86_64-linux-gnu/libssl.so)
    libcrypto.so.1.0.0 needed by /usr/lib/x86_64-linux-gnu/libssl.so
    found libcrypto.so.1.0.0 at /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    libc.so.6 needed by /usr/lib/x86_64-linux-gnu/libssl.so
    found libc.so.6 at /lib/x86_64-linux-gnu/libc.so.6
    libdl.so.2 needed by /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    found libdl.so.2 at /lib/x86_64-linux-gnu/libdl.so.2
    ld-linux-x86-64.so.2 needed by /lib/x86_64-linux-gnu/libc.so.6
    found ld-linux-x86-64.so.2 at /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    ld: warning: cannot find entry symbol _start; not setting start address
    

    You'll get this behavior when you try find it.

So, what happens when you try to find libssl.a actually, what does ld tool perform? You may try to investigate it by running ld -l/home/anz/openssl-1.0.1j/libssl.a --verbose:

ld -l/home/anz/openssl-1.0.1j/libssl.a --verbose`
attempt to open /usr/x86_64-linux-gnu/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib/x86_64-linux-gnu/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib64/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/x86_64-linux-gnu/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/x86_64-linux-gnu/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/local/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/local/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
attempt to open /usr/lib/lib/home/anz/openssl-1.0.1j/libssl.a.so failed
attempt to open /usr/lib/lib/home/anz/openssl-1.0.1j/libssl.a.a failed
ld: cannot find -l/home/anz/openssl-1.0.1j/libssl.a

If you'd know what -l and -L ld-options mean you would know what it does exactly: everything after -l is library name you search and want to link; -L sets a path (appends to linker's own list during linking process) where to search your libraries.

Edit your CMakeLists.txt properly in order to fix this.

VP.
  • 15,509
  • 17
  • 91
  • 161
  • But from where did this `-l` come in the path? – Jackzz Jan 28 '15 at 10:03
  • I get the following message when executing `ld /home/anz/openssl-1.0.1j/libssl.a --verbose` : `attempt to open /home/anaswara/openssl-1.0.1j/libssl.a succeeded. ld: warning: cannot find entry symbol _start; not setting start address`. But `ld -l/home/anz/openssl-1.0.1j/libssl.a --verbose` says it cannot find.. – Jackzz Jan 28 '15 at 10:04
  • Can you show **FULL** `CMakeLists.txt` ? And where this "Cmake configuration window" ? Does this window affects `CXXFLAGS` variable of the `CMakeLists.txt` ? – VP. Jan 28 '15 at 10:08
  • The cmakelists is splitted. The structure of my project is `ABCD->Abc'. The find and include portions of Cmake is written in CMAKelists.txt of ABCD and the target_link_libraries is written in that of Abc. – Jackzz Jan 28 '15 at 10:11
  • The configuration window can be opened from kDevelop. Project->OpenConfiguration. – Jackzz Jan 28 '15 at 10:12
  • I can see nothing in this window to set libraries. Can you give me a screenshot where did you specify them? – VP. Jan 28 '15 at 10:13
  • Once you have loaded the project to kDevlop using Project->Open/import Project-> , the configuration window will have all the needed values. – Jackzz Jan 28 '15 at 10:42
0

While building the project, I am getting the link error as /usr/bin/ld: cannot find -l/home/anz/openssl-1.0.1j/libssl.a

An archive (libssl.a) is a collection of object files. As such, you use it in this instance just like any other object file. There's no need for the -l:

gcc foo.o bar.o -o baz.exe

In your case, something like:

gcc foo.o bar.o /home/anz/openssl-1.0.1j/libssl.a -o baz.exe

I frequently use the same techniques to ensure I'm linking against static version of libraries because its portable between Mac OS X, Linux and BSD. -Bstatic, -L and -l are not portable because OS X always links against a dynamic library if available.

In KDevelop, you just need to find the place where you specify additional object files (because an archive is just a collection of object files).

jww
  • 97,681
  • 90
  • 411
  • 885