Article Directory
Environment and tools
- TBB compilation environment:
Ubuntu18.04
- TBB version: oneTBB-2019_U8
- Cross compilation tool chain: gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu
- Test project construction environment:
Windows7
+交叉编译工具链
+Qt5.9.3
- Operating environment:
Xilinx Zynq UltraScale+ MPSoC
+Ubuntu
Compile
For cross-compiling tool chain, please download the configuration yourself.
Before performing the following steps, please ensure that the following commands can view the version of the compilation chain, which means that the compilation chain configuration is successful:
aarch64-linux-gnu-gcc -v
aarch64-linux-gnu-g++ -v
TBB
Provided to us makefile
, if it is compiled in the target environment, it will detect the environment based on the script interaction, and then automatically configure the compilation parameter rules according to the environment, which is very Reassuring
.
If it is cross-compilation, there is actually no trouble as imagined...
Note : do not need to fully understand tbb
the compiler parameters and rules, and how to automatically depending on the environment the right compiler, and then rewrite it makefile
, it will be a hard thing not to please, especially for makefile初学者
it.
We can achieve cross-compilation through the following instructions:
make CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++
Q&A
-m64 parameter
The first encounter is a cross-compiler tool chain aarch64-linux-gnu-g++
absent -m64
parameters
In my environment, which is in part oneTBB-2019_U8/build/linux.gcc.inc
, simply do the following changes; of course, and I related to the environment, here are for reference only:
ifeq (intel64,$(arch))
# ITT_NOTIFY = -DDO_ITT_NOTIFY
# CPLUS_FLAGS += -m64 $(RTM_KEY)
CPLUS_FLAGS += $(RTM_KEY)
# LIB_LINK_FLAGS += -m64
endif
xxxx.so.x not found
Through sudo find / -name xxxx.so*
search, we found xxxx.so
present in the cross-compiler tool chain, then we "copy" a path to the destination can be renamed.
It is worth note that if a direct copy and rename:
cp xxxxx.so xxxxx.so.x
Then there will only be problems in the compilation process Too many open files
The correct approach should be to establish a soft link:
ln -s xxxxx.so xxxxx.so.x
ld-linux-aarch64.so.1 not found
Not found in the cross compilation chain ld-linux-aarch64.so
But it is actually in the cross compilation tool chain ld.so
The specific path is:
gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/lib/ld-2.23.so
In the same way, just create a soft link.
Then compile successfully~~
But it’s still too early...
undefined reference to “__dlsym”
When writing the test demo, it was found that the compilation failed because of:
undefined reference to "__dlsym"
undefined reference to "__dlopen"
Use nm -D libtbb.so.2
to view libtbb.so.2
library content, the existence of an externally defined or undefined __dlsym
such as:
So where are these functions defined?
Nor found in the associated header file __dlsym
definition, only to find dlsym
and so on.
In the end, I couldn’t find it... So I went to compare the ones lbbtbb.so.2
that can be used normally, and I found that they don’t have this stuff at all!
Then the problem lies in compiling the dynamic library, am I going to do it again?
Using ‘dlopen’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Then I noticed the warning seen in the title, so I linux.gcc.inc
make the following changes in
# PIC_KEY选项加上-ldl
PIC_KEY = -fPIC -ldl
# LIBDL不需要了,注释掉
# LIBDL = -ldl
Again using compiled nm -D libtbb.so.2
to view the contents of a dynamic library
test
Qt Demo
Please refer to the environment Daheng Zhixing Pallas_Qt_mingw32_SDK development environment to build
pro
INCLUDEPATH += xxx\tbb\include
DEPENDPATH += xxx\tbb/lib
LIBS += -Lxxx\tbb/lib \
-ltbb -ltbbmalloc -ltbbmalloc_proxy -ldl
main
As used herein, parallel_for
verify dynamic library is available, is a very simple example.
#include <QCoreApplication>
#include <iostream>
#include <tbb/tbb.h>
using namespace tbb;
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
tbb::parallel_for(1, 10, [](int i){
std::cout << i << std::endl; });
return a.exec();
}
Target environment test
Grant permissions
chmod 777 daheng_tbb_test
carried out
./daheng_tbb_test
Q&A
The following problems occurred during execution:
error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
The reason for the above problem is that we cannot be found in the target environment. tbb库
The method I use is:
-
Put our library in a certain path, for example
/usr/loca/lib
-
And then modify
ld.so.conf
that the implementationvi /etc/ld.so.conf
will be included into our path -
Update, execute
ldconfig
Then run it again:
End
It's finally over!