-
Notifications
You must be signed in to change notification settings - Fork 7
modify code to allow shared object used independently and some minor changes #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
add_library(qpoases_lib SHARED IMPORTED) | ||
set_target_properties(qpoases_lib PROPERTIES | ||
IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}qpOASES${CMAKE_SHARED_LIBRARY_SUFFIX} | ||
IMPORTED_NO_SONAME TRUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment 1:
The IMPORTED_NO_SONAME TRUE
for qpOASES is that, libqpOASES.so
has no SONAME. This might be a reason that here we directly uses the Makefile
instead of CMakeLists.txt
provided by the repo.
(SONAME can be check with readelf -d <library-name> | head -10
to compare libosqp.so
and libqpOASES.so
)
> readelf -d libosqp.so | head -10
Dynamic section at offset 0x1ad90 contains 27 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libosqp.so]
0x000000000000000c (INIT) 0x4000
> readelf -d libqpOASES.so | head -10
Dynamic section at offset 0x75d38 contains 27 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x14000
When not using the IMPORTED_NO_SONAME
, the runtime dynamic linking of the library is based on the relative path, instead of the rpath
. Simply speaking, when you try to run the library / executable in a folder that is not the folder that you run make
command, the loading will be failed.
We can inspect this by running the ldd
over the built liblcqpow.so
:
(no fixing) inside build folder:
>~/Git/LCQPow/build$ ldd ./lib/liblcqpow.so
linux-vdso.so.1 (0x00007ffc4808e000)
lib/libqpOASES.so (0x00007f62c680d000)
...
(no fixing) in some other folder:
>~/Git/LCQPow/build/lib$ ldd ./liblcqpow.so
linux-vdso.so.1 (0x00007ffe1cbef000)
lib/libqpOASES.so => not found
(fixed) everywhere:
>:~/Git/LCQPow/build/lib$ ldd ./liblcqpow.so
linux-vdso.so.1 (0x00007ffca27b1000)
libqpOASES.so => <HOME FOLDER>/Git/LCQPow/build/lib/libqpOASES.so (0x00007f8eeeb6f000)
Some helpful references:
https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_NO_SONAME.html
https://stackoverflow.com/questions/10199045/c-linker-missing-library-when-running-soname-behavior
https://stackoverflow.com/questions/68164903/cmake-to-link-external-library-with-import-soname-ro-import-location
We can use the folder and file sturcture provided in #6 as a simple test: CMakeLists.txt:
Now only linking with shared library of LCQpow is totally fine. |
Thanks for adding this pull request! Looks like a good improvement once we get everything working :) I checked out this pull request, but I couldn't compile. Here is my output
Currently trying to investigate what's happening here. |
Not very sure why things works differently, Maybe because my cmake version is 3.28.3 so something works differently? But surely it has something to do with the include things, especially here: I remove the project-based include include_directories(${PROJECT_NAME}
SYSTEM ${qpoases_include}
SYSTEM ${osqp_include}
) To target-based include I realize a mistake I made here (some bad / not very well written PUBLIC and PRIVATE attribute). Not very sure if this causes this problem in your machine. If it still cannot work, we can re-introduce the project-based include and I think this will go away. |
Some extra hints: add_depencency([target] [ExternalProject]) is meaningless, but add_depencency([target] [imported_target]) is totally fine. add_dependencies(
${PROJECT_NAME}-shared
qpoases_lib
osqp_lib
) for this and other targets is helpful. Running Helpful references: https://stackoverflow.com/questions/31222734/cmake-externalproject-add-and-parallel-builds |
Some quick comments: I still can't the the parallel problem working ( But I am a bit busy in these few days, I will take a look over this later calmly. Anyway this is not a major problem. p.s. |
modify code to allow shared object used independently and some minor changes:
${PROJECT_NAME}-shared
with correct shared object linking dependency on osqp and qpOASES.gcc
argument style linking to target-based linking withadd_library(IMPORTED)
add_dependencies()
of a target over aExternalProject
, which actually does nothing.