Skip to content
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

Enable support for BUILD_SHARED_LIBS on Windows #81

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

traversaro
Copy link
Contributor

The variable CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS used to support BUILD_SHARED_LIBS works fine for all symbols, except static/global variable (see https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html and https://www.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/).

For this reason, the global symbols need to be explicitly exported via __declspec(dllexport) and __declspec(dllimport), that are added via a XLinkExport.h header generated by the generate_export_header CMake function.

Without this fix, linking an executable against the XLink shared library on Windows fails with error:

FAILED: examples/boot_firmware.exe
C:\Windows\system32\cmd.exe /C "cd . && D:\miniforge3\envs\idjlluxonisenv\Library\bin\cmake.exe -E vs_link_exe --intdir=examples\CMakeFiles\boot_firmware.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~4\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo examples\CMakeFiles\boot_firmware.dir\boot_firmware.cpp.obj  /out:examples\boot_firmware.exe /implib:examples\boot_firmware.lib /pdb:examples\boot_firmware.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console  XLink.lib  D:\miniforge3\envs\idjlluxonisenv\Library\lib\libusb-1.0.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && C:\Windows\system32\cmd.exe /C "cd /D D:\src\depthaicorestint1\XLink\build\examples && D:\miniforge3\envs\idjlluxonisenv\Library\bin\cmake.exe -E copy_if_different D:/src/depthaicorestint1/XLink/build/XLink.dll D:/src/depthaicorestint1/XLink/build/examples""
LINK: command "C:\PROGRA~2\MICROS~4\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo examples\CMakeFiles\boot_firmware.dir\boot_firmware.cpp.obj /out:examples\boot_firmware.exe /implib:examples\boot_firmware.lib /pdb:examples\boot_firmware.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console XLink.lib D:\miniforge3\envs\idjlluxonisenv\Library\lib\libusb-1.0.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1120) with the following output:
boot_firmware.cpp.obj : error LNK2019: unresolved external symbol mvLogLevel_default referenced in function main
examples\boot_firmware.exe : fatal error LNK1120: 1 unresolved externals
[35/35] Linking CXX executable tests\multithreading_search_test.exe
ninja: build stopped: subcommand failed.

Copy link
Collaborator

@themarpe themarpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @traversaro !

Headsup @moratom

@themarpe themarpe merged commit 85c306c into luxonis:master Jun 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants