LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-04-2014, 03:46 AM   #1
mr.simo
Member
 
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

Code:
/opt/arm/arm-none-linux-gnueabi/libc/lib/customLibs/
, and into **/usr/lib/**into the ARM system.

Then I copied the header files into

Code:
/opt/arm/arm-none-linux-gnueabi/libc/usr/include/customLibs/
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:

Code:
arm-none-linux-gnueabi-g++ main.cc -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/customLib.so
and I got

Code:
/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/customLib.so
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 09:51 AM.
 
Old 11-04-2014, 09:03 AM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
From man ld:
Quote:
-l namespec
--library=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 customLib.so use:
Code:
-l:customLib.so
If it is named libcustomLib.so you can use:
Code:
-lcustomLib

Last edited by norobro; 11-04-2014 at 09:06 AM. Reason: typo
 
Old 11-05-2014, 07:10 AM   #3
mr.simo
Member
 
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 libcustom.so to libcustom10.so.

As I putted the binary .so files into

Code:
/usr/lib/customLib
and into

Code:
/usr/lib
with symbolic link from

Code:
/usr/lib/customLib
to its parent directory.

Now, when I try to execute:

Code:
arm-angstrom-linux-gnueabi-g++ file.cc -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. libcustom3.so misses libcustom2.so etc. It seems the compiler cannot find the libs...

Then when I execute I get this error:

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

LD_LIBRARY_PATH is

Code:
echo $LD_LIBRARY_PATH
/usr/lib:/usr/lib/trimble:/lib
I am a little bit confused...
 
Old 11-05-2014, 09:50 AM   #4
mr.simo
Member
 
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".
 
  


Reply



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 03:16 AM
Cross compilation (QT libraries) using gcc for Windows arunak Programming 15 04-06-2007 01:12 AM
linking error during cross compilation with ucibc libraries raklo Linux - Kernel 0 03-25-2007 11:48 PM
Linking error while Cross compiling m.harshavardhan Linux - Software 0 07-31-2006 06:08 AM
cross linking files rharris72 Programming 1 11-20-2005 05:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:00 PM.

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