Cmake project yields weird link error LINK1104 in Visual Studio

33 views
Skip to first unread message

Iulian-Nicu Şerbănoiu

unread,
Jun 22, 2025, 5:05:03 PMJun 22
to wx-u...@googlegroups.com
Hi,

I have this Cmakelist.txt for the minimal sample. I copied the minimal.cpp in the folder with the Cmakeflist.txt.

--
CMAKE_MINIMUM_REQUIRED (VERSION 4.0)
PROJECT (minmal)

FIND_PACKAGE(wxWidgets COMPONENTS base core base adv REQUIRED) # other components can be added
INCLUDE(${wxWidgets_USE_FILE})

ADD_EXECUTABLE(minimal WIN32 minimal.cpp)
target_compile_definitions(minimal PUBLIC _UNICODE UNICODE __WXMSW__ WIN32 _DEBUG _WINDOWS WXUSINGDLL NOPCH)
TARGET_LINK_LIBRARIES(minimal ${wxWidgets_LIBRARIES})
--

I am creating a "b" folder in there. Then going into b and issuing cmake .. ;

I open the generated Visual Studio Solution and I get this error:

--
cannot open file 'C:\code\wxminsample\b\Debug\minimal.exe'
--

If I do a project from scratch in Visual Studio with the defines, include/lib dirs and the libraries for linking it works well.

I am using latest wxWidgets (3.3.0) and I only compiled the Debug version using the "build\msw\wx_vc17.sln " (I am using VS 2022 Community Edition).

Has anyone come across this issue?

Thank you,
Iulian

Maarten Bent

unread,
Jun 22, 2025, 5:56:45 PMJun 22
to wx-u...@googlegroups.com
hi,

Maybe minimal.exe is running, so visual studio can't overwrite it?

Maarten
--
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 wx-users+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/wx-users/CAJ5uX7peDkjw%2BRK3U%3D01ca3TuHNwrdniTKSgiOAWz0zBvJovhw%40mail.gmail.com.

Iulian-Nicu Şerbănoiu

unread,
Jun 22, 2025, 11:55:43 PMJun 22
to wx-u...@googlegroups.com
No, it is not even created. Antivirus and all the chatgpt, google suggestions just don't work.

Iulian

PB

unread,
Jun 23, 2025, 10:54:45 AMJun 23
to wx-users
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

PB

unread,
Jun 23, 2025, 12:47:17 PMJun 23
to wx-users
Ooops, sorry the original CMakeLists.txt works (however not optimal it is), I was attempting to link to static wxWidgets.

After telling CMake to use the dynamic build (via -DwxWidgets_LIB_DIR), the generated solution built successfully.

PB
Reply all
Reply to author
Forward
0 new messages