libVector_BLF.so: undefined reference to `Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::ObjectQueue()'
Hello Tobias. When I use cross-compiled(ARM Cortex A53) libVector_blf.so I get an error with the following: usr/lib/libVector_BLF.so: undefined reference to `Vector::BLF::ObjectQueueVector::BLF::ObjectHeaderBase::ObjectQueue()'.But I compiled, built and used on the host (ubuntu 20.04) and did not have any problems. I was able to determine that I was building without issues, here are my build steps:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_STAGING_PREFIX XXX/vector_blf/stage)
set(CMAKE_C_COMPILER XXX/arm-openwrt-linux-gcc)
set(CMAKE_CXX_COMPILER XXX/arm-openwrt-linux-g++)
mkdir -p build_arm
cd build_arm
cmake -DCMAKE_INSTALL_PREFIX=XXX/vector_blf/install
-DCMAKE_INSTALL_RPATH=XXX/vector_blf/lib
./..
make install
With the caveat that I set Dxygen to OFF, bash{.line-numbers} option(OPTION_RUN_DOXYGEN "Run Doxygen" OFF)
which I don't feel is critical to constituting a problem. Looking forward to receiving your questions, thank you!
Comments (9)
-
reporter -
repo owner Hello KudoWu,
somehow I missed your first message from December. Good that you kept working on it.
I’ll look into it. I have the feeling that this symbol is not correctly exported. Template instances are sometimes a bit problematic. I’ll try with the same export options “-wl,--no-undefined” and see if I can fix it.
Bye
Tobias
-
repo owner Hello KudoWu,
Some analysis results I already have.
I have the following in the CMakeLists.txt to ensure that only explicitly exported symbols are exported:
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_VISIBILITY_PRESET "hidden" SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION} VISIBILITY_INLINES_HIDDEN 1)
In ObjectQueue.h I explicitly export the symbol, we’re missing:
/* explicit template instantiation */ extern template class ObjectQueue<ObjectHeaderBase>;
I checked with nm --demangle -D. And that’s interesting. I indeed see no constructor.
$ nm --demangle -D libVector_BLF.so.2.4.1 | grep ObjectQueue 00000000000525ea W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::setFileSize(unsigned int) 0000000000052662 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::setBufferSize(unsigned int) 000000000005218e W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::read() 000000000005256e W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::abort() 0000000000052320 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::write(Vector::BLF::ObjectHeaderBase*) 00000000000520f6 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::~ObjectQueue() 00000000000520f6 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::~ObjectQueue() 00000000000524f4 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::eof() const 0000000000052486 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::good() const 00000000000522b8 W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::tellg() const 000000000005241e W Vector::BLF::ObjectQueue<Vector::BLF::ObjectHeaderBase>::tellp() const
Now the constructor is defines as such:
template <typename T> class VECTOR_BLF_EXPORT ObjectQueue final { public: explicit ObjectQueue() = default; ~ObjectQueue();
So the complete class should be exported and all methods and the destructor are exported in fact, just not the constructor, which is defined with “= default”;
I’ll check further. Let’s see how this turns out ;-)
Bye
Tobias
-
repo owner -
assigned issue to
-
assigned issue to
-
repo owner - changed status to open
-
repo owner The additional linker flag didn’t had no impact for me:
-wl,--no-undefined
I added it to CMakeLists.txt that way:
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -Wl,--no-undefined")
However, already before adding this line, the symbol was not exported.
A constructor defined with “= default” doesn’t need a body/implementation. But maybe it confuses the gcc anyway. So I removed this actually unnecessary line and added default initializers for remaining member variables. Maybe this solves the issue.
I have the fix in the following commit: https://bitbucket.org/tobylorenz/vector_blf/commits/ee80d099100c8d22312ecf99d5ca7b15d58148d8
I also have a branch for this, on top of the master branch: https://bitbucket.org/tobylorenz/vector_blf/branch/fix/issue-43
Can you check if this changes anything on your side?
Bye
Tobias
-
reporter Hello Tobias,
The first thing I want to say is that this method works, and I have been able to compile and run successfully.
It was amazing, we never thought about this aspect, thank you very much for your help.
We guess the reason may be due to optimizations made during compilation or something else.
Anyway, thank you very much!
Bye
KudoWu
-
repo owner Hi KudoWu,
that’s good to hear. Perfect.
I’ve added this patch to the master branch and released v2.4.2 with it.
Thanks,
Tobias
-
repo owner - changed status to resolved
v2.4.2 contains the patch to solve this issue. Thanks to KudoWu for pointing this issue out.
- Log in to comment
The above code may be a bit problematic, but hopefully you can understand the meaning. We make sure that the steps are correct when compiling.
Recently, after testing, we found that adding options such as -wl,--no-undefined when compiling did not pass when compiling the Vector_Blf library, and the undefined is File.
Also we made sure that our toolchain supports all the features of C++11, and that the default constructor has been tested and it works.