Re: Cmake project yields weird link error LINK1104 in Visual Studio
PB <[email protected]> Mon, 23 Jun 2025 07:54:45 -0700 (PDT)
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Iulian,
if I use your CMakeLists.txt verbatim (using MSVS 2022 Community and
wxWidgets 3.3.0), I get a bunch of linking errors.
I have generated the solution with
cmake -G "Visual Studio 17 2022" -DCMAKE_CONFIGURATION_TYPES=Debug
-DwxWidgets_ROOT_DIR=D:\Dev\Desktop\Lib\wxWidgets-3.3.0
-DwxWidgets_CONFIGURATION=mswud -S . -B ./cmake-build-vc17_x64_DLL
However, when I removed the extraneous target_compile_definitions() call
(these flags are not needed and the needed ones are set automatically), the
build went just fine.
Of course, your CMakeLists.txt has a bunch of other issues, but I guess
this is just your minimum example. If not, I suggest checking the official
wxWidgets docs to make it correct, even if only for Windows and MSVS. For
example, Windows only CMakeLists.txt could look something like this:
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(minimal)
find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG)
if(wxWidgets_USE_FILE)
include(${wxWidgets_USE_FILE})
endif()
set(SOURCES minimal.cpp minimal.rc)
add_executable(${PROJECT_NAME} WIN32 ${SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
)
target_link_libraries(${PROJECT_NAME} PRIVATE ${wxWidgets_LIBRARIES})
if(MINGW) # work around the breaking change in wxWidgets 3.3
target_link_libraries(${PROJECT_NAME} PRIVATE gdiplus msimg32)
endif()
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE wxUSE_RC_MANIFEST
wxUSE_DPI_AWARE_MANIFEST=2)
if(MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE
_CRT_SECURE_NO_DEPRECATE _CRT_NON_CONFORMING_SWPRINTFS
_SCL_SECURE_NO_WARNINGS)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /MP)
target_link_options(${PROJECT_NAME} PRIVATE /MANIFEST:NO)
else() # GCC or clang
target_compile_options(${PROJECT_NAME} PRIVATE
-Wno-deprecated-declarations)
endif()
endif()
If you did not build wxWidgets with CMake, you need to remove CONFIG from
find_package() call. File minimal.rc should contain also #include
"wx/msw/wx.rc".
Best,
PB
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/5f14601d-a812-4d37-97d7-97be6743d6b3n%40googlegroups.com.