On 15.06.19 21:33, William Zeitler wrote: > In the example below, two lines are marked "COMMENT ME OUT": one in > hello_c/main.cpp and the other in hello_c/CMakeLists.txt. If you comment > these out, the reference to the hello_lib library is removed; the > project builds and the executable executes on Windows 10 without a > libstdc++ dependency. If you uncomment the two lines, the function in > the hello_lib library is linked in; the project builds, but won't > execute on Windows 10 due to the libstdc++ dependency. (Note: in > powershell it silently fails, in an old-school dos/cmd box it displays > an error message.)
I think your problem is that CMAKE_CXX_FLAGS are only used when compiling, not linking, so your hello_lib is linked without the "-static -static-libgcc -static-libstdc++" options and thus links against the shared libstdc++. You could try either of the following: 1) Add a "target_link_libraries(hello_lib -static-libgcc -static-libstdc++)". 2) Add "string(APPEND CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++)" to your project. Note that this will probably need to be done before defining any of your (library) targets. Also note that this will link any shared library in your project with the static libstdc++, which may or may not be what you want. Disclaimer - I haven't tried if any of this actually solves your problem; I just think it should. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake