Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-04-2014, 04:46 AM   #1
Registered: Feb 2010
Posts: 78

Rep: Reputation: 0
Linking custom libraries with g++ and cross compilation

I know linking external custom libraries can be painfull and in fact it is..

I have sombe libraries wich I have to use in my next program, I am trying do link these libraries but nothing works fine.

First of all I am compiling from an x86 with arm-none-linux-gnueabi (installed into /opt/arm/) , so I will have to move the binaries to another machines. The standard process works always fine for Linux system binaries.

On my x86 system I have copied the custom library binaries into

, and into **/usr/lib/**into the ARM system.

Then I copied the header files into

on the x86 system and then into **/usr/inlcude** on the ARM system, as I did for the library binaries.

When I compile with make on the x86 machine, I execute:

arm-none-linux-gnueabi-g++ -o main -I /opt/arm/arm-none-linux-gnueabi/libc/usr/include/customLibs -L /opt/arm/arm-none-linux-gnueabi/libc/lib/customLibs -l /opt/arm/arm-none-linux-gnueabi/libc/lib/customLibs/
and I got

/opt/arm/bin/../lib/gcc/arm-none-linux-gnueabi/4.8.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -l/opt/arm/arm-none-linux-gnueabi/libc/lib/customLibs/
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
However the library is into the path...

What's wrong with my command line arguments ?
Thank you in advance.

Last edited by mr.simo; 11-05-2014 at 10:51 AM.
Old 11-04-2014, 10:03 AM   #2
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
From man ld:
-l namespec
Add the archive or object file specified by namespec to the list of files to link. This
option may be used any number of times. If namespec is of the form :filename, ld will search
the library path for a file called filename, otherwise it will search the library path for a
file called libnamespec.a.
If your library is named use:
If it is named you can use:

Last edited by norobro; 11-04-2014 at 10:06 AM. Reason: typo
Old 11-05-2014, 08:10 AM   #3
Registered: Feb 2010
Posts: 78

Original Poster
Rep: Reputation: 0
Hi norobro,

Thank you for your response.

I already done that, it works better, but it seems that when I try to compile, a lot of files are not encountered..
I will explain better the situation.

There are various binary files of this shared libraries, totally 10, but this is irrelevant I think, let's name them to

As I putted the binary .so files into

and into

with symbolic link from

to its parent directory.

Now, when I try to execute:

arm-angstrom-linux-gnueabi-g++ -o file -L /usr/lib/customLibs -lcustom1 -lcustom2 -lcustom3 -lcustom4 -lcustom5 -lcustom6 -lcustom7 -lcustom8 -lcustom9 -lcustom10 -lpthread -ldl -lrt
linking the libs in order (because I have to respect a determine order) it compiles but the compiler warns about some of these libraries are missing others, i.e. misses etc. It seems the compiler cannot find the libs...

Then when I execute I get this error:

./file: error while loading shared libraries: cannot open shared object file: No such file or directory is the first lib the compiler cannot find during compilation process.


I am a little bit confused...
Old 11-05-2014, 10:50 AM   #4
Registered: Feb 2010
Posts: 78

Original Poster
Rep: Reputation: 0
Problem solved.

The libraries were not linked in the properly order, because who gave me these libs did not specify the correct order...

I solved the order by "reverse engineering".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Build a custom distro with custom boot and libraries adrian2009 Linux - Distributions 3 08-09-2012 04:16 AM
Cross compilation (QT libraries) using gcc for Windows arunak Programming 15 04-06-2007 02:12 AM
linking error during cross compilation with ucibc libraries raklo Linux - Kernel 0 03-26-2007 12:48 AM
Linking error while Cross compiling m.harshavardhan Linux - Software 0 07-31-2006 07:08 AM
cross linking files rharris72 Programming 1 11-20-2005 06:24 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration