-
Notifications
You must be signed in to change notification settings - Fork 54
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
How to link dylib in NAppGUI project #165
Comments
Hi @akacastor! You have to add these lines to your
In this case you can use your shared-lib as static-lib
Cross-platform static linkingFor Windows/Linux the process is the same, but you have to take into account this details:
Take a look to this header: https://github.com/frang75/nappgui_src/blob/main/src/core/core.def |
Thank you for the quick and helpful answer! Using Another macOS question - can I include the .dylib inside the application bundle, so the library doesn't have to be installed separately from the application? From some reading, I think it is possible, for example: https://stackoverflow.com/questions/33333628/how-can-i-bundle-a-dylib-within-a-mac-app-bundle-in-qt There are a few issues I don't fully understand: Where should the .dylib be placed? I guess within How to copy the .dylib into the application bundle as part of the build process? How to set RPATH correctly for the .dylib if it is inside the application bundle? Is there a CMake directive to specify the correct RPATH during compilation, or would it be done using by calling |
Try this, It works for the
You can check that the RPATH is written correctly using otool
For Windows it is a bit simpler. Just save a copy of the DLL in the same directory as the executable. Windows, by default, first looks for DLLs in the same directory as the executable. |
Using the example above, I am able to build my app for macOS with the .dylib included in the bundle. Thank you! One issue I ran into was that the .dylib was not compiled by me, and therefore not signed by me, and then code signing for the app bundle would fail because of the signature mismatch.
This was solved by replacing the signature on the .dylib with my own signature. Conveniently I copied the command line from the above CMake output and specified my .dylib filename.
With the .dylib correctly signed, the build process succeeds and the app bundle includes the .dylib and the signatures match. |
I'm glad it finally works. I've never had this problem before, as I don't usually use third-party DLLs. But I'll make a note of this idea in case I ever encounter this problem. |
One very small 'loose end' I have found with including a .dylib inside the .app bundle - the RPATH from The result functions properly, as the .dylib is still found, but in my case the path used for The superfluous RPATH from At this time, my solution if I need to distribute a binary without the target_link_libraries RPATH is to manually run |
Thanks for sharing. I'll keep this case in mind for future build system revisions on macOS. I'll see if I can integrate a CMake-based solution for this case. |
I have a .dylib and .h file for a third-party library that I want to link with my NAppGUI project on macOS.
What should I add to CMakeLists.txt in order to link a .dylib with my application?
Follow-up question: Is the process the same for macOS and other platforms (Linux, Windows)?
The text was updated successfully, but these errors were encountered: