LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to compile a program for different target machine than host machine? (https://www.linuxquestions.org/questions/programming-9/how-to-compile-a-program-for-different-target-machine-than-host-machine-4175616470/)

josarlo84 10-26-2017 11:22 PM

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?

fatmac 10-27-2017 06:06 AM

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?

rtmistler 10-27-2017 08:31 AM

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.

NevemTeve 10-27-2017 09:18 AM

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

Some details, please?

josarlo84 10-27-2017 10:33 AM

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.

NevemTeve 10-27-2017 11:24 AM

(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?

josarlo84 10-27-2017 11:45 AM

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.

rtmistler 10-27-2017 12:02 PM

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

NevemTeve 10-27-2017 12:38 PM

How about installing a newer version of boast? Normally a newer version of a library should provide the functionality of an older version.

josarlo84 10-27-2017 01:22 PM

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.

josarlo84 10-27-2017 01:24 PM

Quote:

Originally Posted by NevemTeve (Post 5774466)
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 :banghead:.

rtmistler 10-27-2017 01:37 PM

Quote:

Originally Posted by josarlo84 (Post 5774486)
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 (Post 5774486)
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.

rtmistler 10-27-2017 01:39 PM

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?

NevemTeve 10-27-2017 02:04 PM

@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.)

josarlo84 10-27-2017 02:07 PM

Quote:

Originally Posted by rtmistler (Post 5774496)
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 (Post 5774495)
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.


All times are GMT -5. The time now is 04:12 AM.