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

Building shared library on Windows with MSVC+cmake gives lots of linker warnings #995

Closed
sveinse opened this issue Jan 1, 2025 · 1 comment
Labels
build-cmake CMake build system P1 Priority: Highest windows Affects MS Windows
Milestone

Comments

@sveinse
Copy link
Contributor

sveinse commented Jan 1, 2025

Describe the bug

Building portaudio on Windows with MSVC & cmake as a shared library gives lots of warnings about export symbols defined multiple times. An example of the warning:

<path>/build/portaudio/build/portaudio.dir/Debug/exports.def : warning LNK4197:
export 'Pa_WriteStream' specified multiple times; using first specification
[<path>\build\portaudio\build\portaudio.vcxproj]

To Reproduce

  1. Install MSVC Visual Studio or similar on Windows.

  2. Check out portaudio code from git

  3. Configure and build on windows.

     cd portaudio
     $cmake -G "Visual Studio 17 2022" -A x64 \
         -DCMAKE_BUILD_TYPE=RelWithDebInfo \
         -DPA_BUILD_SHARED_LIBS=ON -S . -B build
     $cmake --build build --config RelWithDebInfo
    

($cmake is a shortcut to the cmake provided by MSVC, which on my system is c:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Cmake\bin\cmake.exe)

Expected behavior

Successful build without any warnings

Actual behavior

Observe 57 warnings during linking, for each of the exported symbol from PA. It doesn't look like the warning actually affects the output and the generated shared library seems to work as expected.

Desktop (please complete the following information):

  • OS: Windows 11. Compiling all Windows Host APIs
  • PortAudio version: git master commit aa1cfb0

Additional context

A fix for the problem is given by the following patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b9ce82..725cac8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -458,7 +458,7 @@ set_target_properties(portaudio PROPERTIES
   PUBLIC_HEADER "${PORTAUDIO_PUBLIC_HEADERS}"
   MACOSX_FRAMEWORK_IDENTIFIER com.portaudio
   FRAMEWORK_VERSION A
-  WINDOWS_EXPORT_ALL_SYMBOLS TRUE
+  WINDOWS_EXPORT_ALL_SYMBOLS FALSE
   VERSION ${PROJECT_VERSION}
   SOVERSION 2
 )

believe using WINDOWS_EXPORT_ALL_SYMBOLS TRUE is not wanted since portaudio define the symbols in cmake\portaudio.def.in. If this is wanted, a PR can be made.

@RossBencina RossBencina added build-cmake CMake build system windows Affects MS Windows labels Jan 17, 2025
@RossBencina
Copy link
Collaborator

Hi Svein,

The docs for WINDOWS_EXPORT_ALL_SYMBOLS say:

Enable this boolean property to automatically create a module definition (.def) file with all global symbols found in the input .obj files for a SHARED library (or executable with ENABLE_EXPORTS) on Windows. The module definition file will be passed to the linker causing all symbols to be exported from the .dll.

https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html

Since we supply our own .def file, I agree that WINDOWS_EXPORT_ALL_SYMBOLS should be set to false. A PR with your proposed fix would be appreciated.

@RossBencina RossBencina added this to the V19.8 milestone Jan 17, 2025
@RossBencina RossBencina added the P1 Priority: Highest label Jan 30, 2025
RossBencina added a commit to RossBencina/portaudio that referenced this issue Jan 31, 2025
…def file. fixes PortAudio#995 (multiple export linker warnings) thanks @sveinse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-cmake CMake build system P1 Priority: Highest windows Affects MS Windows
Projects
None yet
Development

No branches or pull requests

2 participants