Linking Issue Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
User avatar
sajid
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Jan 27, 2023 5:43 pm

Linking Issue

Post by sajid »

I am using a cmake script and In the script I am using fetchContent module to build the wxwidgets library in Ubuntu 22.04 and windows 11.My build options are Release + static + monolithic + unicode. In windows I am using vscode + MSVC and in the ubuntu I am using vscode+gcc. I am successfully able to build the wxwidgets library and Link it with the project. But in windows 11 the library is built successfully but when it is linking with the project . It is producing a linker error.
fatal error LNK1104: cannot open file 'wxbase32u.lib'.
My build option is monolithic, why is it asking for wxbase32u.lib. My cmake Script is:

Code: Select all

cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(PRACTICE LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(wxWidgets_USE_STATIC 1)
set(wxBUILD_SHARED OFF)
set(wxBUILD_MONOLITHIC ON)

# superbuild using FetchContent
include(FetchContent)
FetchContent_Declare(
    wxWidgets
    GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git
    GIT_TAG v3.2.1
)
FetchContent_GetProperties(wxwidgets)
if(NOT wxwidgets_POPULATED)
    FetchContent_Populate(wxwidgets)
    add_subdirectory(${wxwidgets_SOURCE_DIR} ${wxwidgets_BUILD_DIR})
endif()

set(SRCS src/frame.cpp src/main.cpp)
add_executable(main WIN32 ${SRCS})

if(WIN32)
    target_include_directories(main PRIVATE ${wxWidgets_SOURCE_DIR}/include/msvc)
endif()
target_include_directories(main PRIVATE ${wxWidgets_SOURCE_DIR}/include)
target_compile_definitions(main PRIVATE _UNICODE=1)
target_link_libraries(main PRIVATE wx::mono)
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Linking Issue

Post by PB »

I have no experience with CMake fetch, but I think the problem may be here:
sajid wrote: Tue Feb 07, 2023 10:29 am

Code: Select all

if(WIN32)
    target_include_directories(main PRIVATE ${wxWidgets_SOURCE_DIR}/include/msvc)
endif()
Adding MSVC-specific include folder means that MSVC-specific setup.h will be #included by the main setup.h file. This MSVC-specific setup.h automatically links wxWidgets libraries; however, it has no idea you are using monolithic build (as wxMONOLITHIC is not set by CMake and thus was not #defined as 1) and thus tries to link against multilib libraries. I suggest removing the quoted block from your CMakefile. That setup.h exists only for autolink convenience, and is not needed with CMake (and the code is also incorrectly guarded with WIN32 instead of MSVC).
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Linking Issue

Post by ONEEYEMAN »

Hi,
My suggestion is to remove monolithic.
The ONLY place where it needed is when building CodeBlocks itself.
You life will be so much easier.

Thank you.
User avatar
sajid
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Jan 27, 2023 5:43 pm

Re: Linking Issue

Post by sajid »

PB wrote: Tue Feb 07, 2023 1:00 pm I have no experience with CMake fetch, but I think the problem may be here:
sajid wrote: Tue Feb 07, 2023 10:29 am

Code: Select all

if(WIN32)
    target_include_directories(main PRIVATE ${wxWidgets_SOURCE_DIR}/include/msvc)
endif()
Adding MSVC-specific include folder means that MSVC-specific setup.h will be #included by the main setup.h file. This MSVC-specific setup.h automatically links wxWidgets libraries; however, it has no idea you are using monolithic build (as wxMONOLITHIC is not set by CMake and thus was not #defined as 1) and thus tries to link against multilib libraries. I suggest removing the quoted block from your CMakefile. That setup.h exists only for autolink convenience, and is not needed with CMake (and the code is also incorrectly guarded with WIN32 instead of MSVC).
Thanks a lot Man.
Post Reply