NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Cross-compiling a C++ code that uses openssl libraries for cRIO 9068

Solved!
Go to solution

Hello all,


I am trying to cross-compile a large C++ code that uses openssl for cRIO 9068 release 2013. I found out that the cRIO has the libcrypto and libssl libraries install under their Windows-style names in:

•/usr/local/natinst/lib/libeay32.so

•/usr/local/natinst/lib/libssleay32.so

In order to cross-compile my c++ code in ubuntu, i installed the corresponding cross compiler using the  following command

sudo apt-get install g++-arm-linux-gnueabi

I also copied the above openssl libraries from the cRIO to /usr/arm-linux-gnueabi/lib in my ubuntu machine and used the -leay32 -lssleay32 link options. However, i got the following linker error.

cannot find -leay32 and -lssleay32

However, i managed to successfully compile a C code using these same options on the eclipse edition provided by NI.

So my question is, how do we cross-compile a C++ code for cRIO 9068 that uses the provided openssl libraries in Ubuntu? What is the cross-compiler to use and what compiler options do I need  to specify for my make file.

Thank you,

ttesfay

0 Kudos
Message 1 of 24
(16,168 Views)

ttesfay,

First and foremost, I would check to make sure that you can compile and run a simple HelloWorld-type C/C++ file. Some things that could trip you up include:

  • Wrong ABI (e.g. if it is a hard-float toolchain)
  • Too new a toolchain (the resulting binary will expect symbols that are missing from the system's C library)
    • Note that the system libraries on 2013 include glibc 2.11
  • Possibly others

Once you determine that you are able to compile and run a simple application, I would try to invoke the tools directly and, using a tool like strace, follow the compilation process to see why it fails to find the libraries (you may need to provide some additional library search paths via -L arguments/configuration in Eclipse)

Message 2 of 24
(7,901 Views)

By the way, I was able to track down a link for the linux version of the toolchain that was used in the 2013 Eclipse installer:

http://www.codesourcery.com/sgpp/lite/arm/portal/package6488/public/arm-none-linux-gnueabi/arm-2010q...

0 Kudos
Message 3 of 24
(7,901 Views)

Thank you BradM,

The hints were indeed very helpful. I cross-compiled a simple c++ program on my ubuntu host and it executed without any problem in the crio. I also managed to cross-compile my code that uses the openssl libraries by using the -L option and it worked fine. However - like you said - it looks like the toolchain in my ubuntu is too new. When i tried to execute the resulting binary in the crio, i got the following errors:

./myexec: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./myexec)

./myexec: /lib/libc.so.6: version `GLIBC_2.17' not found (required by ./myexec)

I used the -static-libstdc++  compiler option to remove the first problem. I guess i need to have a glibc 2.11 (as per your info) in my host machine in order to remove the second problem.

1. Is it possible to "downgrade" only the glibc in the toolchain i have installed in my host machine (arm-linux-gnueabi-g++-4.7) from glibc 2.17 to glibc 2.11?

2. How can i use the linux version of the toolchain that you provided above?

Thank you again,

ttesfay

0 Kudos
Message 4 of 24
(7,901 Views)
Solution
Accepted by topic author ttesfay

Glad to see we made some progress!

Basically I would recommend downloading and extracting the archive. Once you do that, you'll have a folder that contains the cross-compile tools that you can then configure Eclipse to use in much the same way that you did so for the apt-installed cross-compile toolchain.

One difference is if you just configured a cross-compilation prefix for Eclipse since, e.g., arm-*-linux-gnueabi- tools were on the $PATH variable (you could just run "arm-whatever-linux-gnueabi-gcc -v" from any folder), you would either need to add the new path to the PATH environment variable or provide the full paths to the tools when configuring Eclipse.

0 Kudos
Message 5 of 24
(7,901 Views)

Yeah, I just got finished setting up a fresh Eclipse Luna download with the toolchain I pointed out, it's pretty much what I expected. Let me know if you run into issues configuring things.

0 Kudos
Message 6 of 24
(7,901 Views)

Thank you BradM!

I used the toolchain to cross-compile my code from the command line (using my Makefile). I had to copy the openssl headerfiles folder to the toolchain's include folder and specify the include path using -I. I also copied the openssl libraries from my cRIO to the toolchain's lib folder and specify the path to the cross-compiler using -L. After that everything worked like a charm! I wanted to compile the code from the command line because the make file generates several executables. Thus I did not want to create several projects on eclipse for each one of them.


Thank you once more!

ttesfay

0 Kudos
Message 7 of 24
(7,901 Views)

Makes total sense. I suppose I need to be careful about assuming that folks using NI stuff will automatically opt for the more-UI-centric approach

0 Kudos
Message 8 of 24
(7,901 Views)

I have almost the same problem which ttesfay had. But I don't know how to proceed because I'm very inexperienced with cross-compiling.

My target system is myRIO with the OS: NI Linux Real-Time ARMv7-A.

My host operating system is: Linux-Ubuntu (64bit) or Windows 8.1 (64bit)

I managed to cross-compile a simple C++ program with using Eclipse (NI version) on Windows.

Now I want to cross-compile a C++ Source Code with many dependencies and using external libraries like boost, libxml2, Eigen, CGAL, Coin3D.

I downloaded the toolchain which was posted before but I don't know how to use it on Linux.

Do you recommend to use a program like Cmake or Buildroot to generate Makefiles?

-If yes, do you have a good instruction to use it with myRIO?

-If no, can you please tell me how to exactly proceed to cross-compile everything, to make all the dependencies and to build it?

@ttesfay: How did you exactly proceed to get everything working? Perhaps you can send me the folder of your simple c++ program.

I would be very glad if someone can give me precise instructions.

Thank you,

Oemer

0 Kudos
Message 9 of 24
(7,901 Views)

oemergoecer, welcome.

With a project as complex as that, this is an area where I think you're going to spend more time fighting configuration issues if you attempt to build the software through a cross-compile-enabled IDE than is really warranted. If I were to make a suggestion, I would recommend you get the tools that you need on the target itself and build (and then install) the needed libraries and headers on your myRIO (yourRIO?).

There are some good instructions around these forums, but be sure to find one that matches your particular release (are you using 2013/sp1 or 2014?)

Once you've gotten things squared away, I would recommend backing up an image of the controller using the System Image utility VIs.

0 Kudos
Message 10 of 24
(7,901 Views)