LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2017, 11:22 PM   #1
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Rep: Reputation: Disabled
How to compile a program for different target machine than host machine?


At work, we have a project that compiles and runs on Debian Jessie. Typically, we use build servers for compiling, but I would like to move compilation to my own Linux box. I have tried to compile the program on Mint Sarah and Debian Stretch with no luck. I have tried installing Jessie, but the drivers are too out-of-date for my Linux box.

I can compile on Stretch, but won't run on the target machines because the shared library versions don't match. When I match library versions in Sarah and Stretch to the ones in Jessie I get linking errors.

So, can I compile a program for Debian Jessie on another Debian variant with newer libraries? I am coming to the conclusion that it is not. I am looking at using a VM, but if I go that route I want something that is light weight and preferably using only the command line. Any suggestions?
 
Old 10-27-2017, 06:06 AM   #2
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,510

Rep: Reputation: Disabled
Cross compiling, or is it just another version of Linux, use an older version of gcc possibly?
Install the same version of the target machine in a VM & compile it in there?
 
Old 10-27-2017, 08:31 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
The reason why you have build servers is that they are configured to compile for the exact outcome desired.

Ask the persons who set up the build servers to help you with this. It's not that you haven't given us enough information (you haven't), but it is also that you cannot give us enough information. I feel there are things which you do not fully know about how those build servers are configured.
 
1 members found this post helpful.
Old 10-27-2017, 09:18 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,878
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
> I have tried to compile the program on Mint Sarah and Debian Stretch with no luck.

Some details, please?
 
Old 10-27-2017, 10:33 AM   #5
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Sorry for the shotgun approach. The following are packages on the build servers. I have installed these on my Debian Stretch (matching versions):
  • gsoap=2.8.17-1
  • g++=4:4.9.2-2
  • libboost-dev=1.55.0.2
  • libstdc++-4.9-dev
  • libssl-dev=1.0.1t-1+deb8u6
  • libpcap-dev=1.6.2-2
  • libmysql++-dev=3.2.1+pristine-1
  • libxerces-c-dev=3.1.1-5.1+deb8u3
  • xsdcxx=4.0.0-1
  • libxerces-c3.1=3.1.1-5.1+deb8u3

When I try to link the program "foo" together, I get the following errors:
Code:
g++ -ggdb -DWITH_OPENSSL -std=c++11 -O3 ../build/obj/Foo.o -L../build/obj/ -L/home/josarlo84/.local/lib -lpthread -lssl -lcrypto -lgsoapssl++ -lmysqlclient -lboost_thread -lboost_system -lpcap -lboost_date_time -lboost_filesystem -lboost_regex -lxerces-c ../build/obj/foo_api.a ../build/obj/shared_api.a -o ../build/Foo
../build/obj/foo_api.a(FooApiHandler.o): In function `boost::cpp_regex_traits<char>::transform_primary(char const*, char const*) const':
/home/josarlo84/.local/include/boost/regex/v4/cpp_regex_traits.hpp:923: undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
../build/obj/foo_api.a(FooApiHandler.o): In function `boost::cpp_regex_traits<char>::transform(char const*, char const*) const':
/home/josarlo84/.local/include/boost/regex/v4/cpp_regex_traits.hpp:919: undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
../build/obj/foo_api.a(FooApiHandler.o): In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_prefix()':
/home/josarlo84/.local/include/boost/regex/v4/perl_matcher_common.hpp:333: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)'
../build/obj/foo_api.a(FooApiHandler.o): In function `perl_matcher':
/home/josarlo84/.local/include/boost/regex/v4/perl_matcher.hpp:374: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
../build/obj/foo_api.a(FooApiHandler.o): In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_match()':
/home/josarlo84/.local/include/boost/regex/v4/perl_matcher_non_recursive.hpp:991: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)'
collect2: error: ld returned 1 exit status
Makefile:50: recipe for target '../build/Foo' failed
make: *** [../build/Foo] Error 1
Boost headers and libraries and installed at /home/josarlo84/.local so as not to interfere with the boost libraries needed for Stretch. I get similar linking errors in Mint. I cannot figure out how to resolve this linking error. If it can't be resolved with my configuration, then I would want to look into a VM solution.
 
Old 10-27-2017, 11:24 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,878
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
(You know what Gautama Buddha said: C++ leads to suffering)
Are you sure you cannot install these components from official packages instead of manually copying something into nonstandard places?
 
Old 10-27-2017, 11:45 AM   #7
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
All packages are installed using aptitude with Jessie repository except for boost libraries. I manually downloaded and compiled boost because when I tried to install from apt-get Jessie and Stretch versions clashed.
 
Old 10-27-2017, 12:02 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
The other items you may need are:
  1. The Makefiles, which I assume you have as part of the source
  2. The environment variables established on these build servers
  3. The specific link libraries which these build servers are using for these builds. It's not about mimicking the installed applications or libraries from the build server, but mimicking the libraries which are being used specifically for these builds
 
Old 10-27-2017, 12:38 PM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,878
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
How about installing a newer version of boast? Normally a newer version of a library should provide the functionality of an older version.
 
Old 10-27-2017, 01:22 PM   #10
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
The Makefiles, which I assume you have as part of the source
Correct, I have those as apart of source

Quote:
The environment variables established on these build servers
How can I tell which environment variables are being used?

Quote:
The specific link libraries which these build servers are using for these builds. It's not about mimicking the installed applications or libraries from the build server, but mimicking the libraries which are being used specifically for these builds
I can get Foo to compile and link, however, when I run it on the target machines it attempts to access the wrong version of shared libraries. The list I posted is from that trial and error -- build, run, identify mismatched library, install missing library version, repeat. The last mismatched library was libstdc++.so.6. The errors I got was GLIBCXX_3.4.21 not found: required by ./Foo, and GLIBCXX_3.4.22 not found: required by ./Foo.

After downgrading g++ from 4.6 to 4.4, to match the build servers, I get the linking errors described above.
 
Old 10-27-2017, 01:24 PM   #11
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
How about installing a newer version of boast? Normally a newer version of a library should provide the functionality of an older version.
I could do this, but when I try to run on our target machines, it tries to match the latest version of boost, and not the ones installed .
 
Old 10-27-2017, 01:37 PM   #12
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by josarlo84 View Post
How can I tell which environment variables are being used?
This is the part where I told you to speak to your build system administrators. Remember, when you install tools, there's usually a README that tells you what environment variables those tools require. So ... you can either continue to hunt and peck at it, or you can look it up/ask. Is there a problem asking?
Quote:
Originally Posted by josarlo84 View Post
I can get Foo to compile and link, however, when I run it on the target machines it attempts to access the wrong version of shared libraries. The list I posted is from that trial and error -- build, run, identify mismatched library, install missing library version, repeat. The last mismatched library was libstdc++.so.6. The errors I got was GLIBCXX_3.4.21 not found: required by ./Foo, and GLIBCXX_3.4.22 not found: required by ./Foo.

After downgrading g++ from 4.6 to 4.4, to match the build servers, I get the linking errors described above.
You can likely get anything to "compile", as well as "link" using the proper libraries.

HOWEVER, as you're saying, they won't properly run on the target.

Now ... this target is either matching the CPU from where you're compiling, or it is entirely different. Once again, we don't know if this is cross compilation, or something else.

Just because you link something successfully only means that you satisfied the library requirements on the build machine you're using. However if those linked-to libraries are not matching the ones on the target environment, then they won't work.
 
Old 10-27-2017, 01:39 PM   #13
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Forget distribution, you've already described this.

What are the hardware specifications for your build machine? The one you are using.

What are the hardware specifications for your target?
 
Old 10-27-2017, 02:04 PM   #14
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,878
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
@OP: I cannot follow you. If you want to use the program on computer X, then compile it from source on computer X. That's how things work in Unix (unlike Windows, for example.)

Last edited by NevemTeve; 10-27-2017 at 02:05 PM.
 
1 members found this post helpful.
Old 10-27-2017, 02:07 PM   #15
josarlo84
LQ Newbie
 
Registered: Oct 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Forget distribution, you've already described this.

What are the hardware specifications for your build machine? The one you are using.

What are the hardware specifications for your target?
Both the target and the host have the same hardware architecture. I can (and have) installed Debian Jessie on my host machine and can build and run Foo using Jessie packages installed with aptitude. I only have problems when I upgrade to Stretch or Mint.

Quote:
Originally Posted by rtmistler View Post
This is the part where I told you to speak to your build system administrators. Remember, when you install tools, there's usually a README that tells you what environment variables those tools require. So ... you can either continue to hunt and peck at it, or you can look it up/ask. Is there a problem asking?You can likely get anything to "compile", as well as "link" using the proper libraries.
The system administrator told me that I just needed to match package versions.
 
  


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
Compile binaries in GUEST for HOST machine? emon_lq Gentoo 11 12-29-2016 03:48 AM
program segfault occurs only on host machine dayalan_cse Programming 1 03-24-2016 01:13 AM
Iptables: route web traffic of virtual machine through local proxy of host machine lola.hipf Linux - Networking 1 10-26-2014 07:09 PM
need help to create another machine under vmware which host machine is gateway server iftikhar.tutul Linux - Server 5 01-31-2014 08:04 PM
How to configure the serial port of my virtual machine with host machine. akram Linux - Newbie 4 07-31-2009 10:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:11 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