CMake 3.28 has been released with first class support for C++ 20 modules (using Clang >= 17 at least). I'm getting several errors like this in the build output.
[ ... snip ... ]
[build] [10/12] Building CXX object CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o
[build] FAILED: CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o CMakeFiles/Modules.dir/Debug/HS.Util.pcm
[build] /usr/bin/clang++ -D_FILE_OFFSET_BITS=64 -D__WXGTK__ -DCMAKE_INTDIR=\"Debug\" -I/home/geoffrey/dev/scratch/t/include -I/home/geoffrey/dev/scratch/t/modules -I/home/geoffrey/dev/scratch/t/src/include -I/home/geoffrey/dev/scratch/t/src/modules -I/usr/local/lib64/wx/include/gtk3-unicode-3.3 -isystem /home/geoffrey/dev/sys/vcpkg/installed/x64-linux/include -isystem /usr/local/lib64/wx/include/gtk3-unicode-static-3.3 -isystem /usr/local/include/wx-3.3 -pthread -g -std=c++20 -MD -MT CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o -MF CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o.d @CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o.modmap -o CMakeFiles/Modules.dir/Debug/src/modules/HSUtil.cpp.o -c /home/geoffrey/dev/scratch/t/src/modules/HSUtil.cpp
[build] In file included from /home/geoffrey/dev/scratch/t/src/modules/HSUtil.cpp:35:
[build] In file included from /usr/local/include/wx-3.3/wx/wx.h:23:
[build] In file included from /usr/local/include/wx-3.3/wx/event.h:29:
[build] In file included from /usr/local/include/wx-3.3/wx/any.h:599:
[build] /usr/local/include/wx-3.3/wx/datetime.h:752:17: error: 'wxDateTime' has different definitions in different modules; first difference is defined here found method 'IsValid' with body
[build] 752 | inline bool IsValid() const { return m_time != wxLongLong(wxINT64_MIN); }
[build] | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] /usr/local/include/wx-3.3/wx/datetime.h:752:17: note: but in 'HS.Debug.<global>' found method 'IsValid' with different body
[build] 752 | inline bool IsValid() const { return m_time != wxLongLong(wxINT64_MIN); }
[build] | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ... snip ... ]
I've been stuck on this for about 5 days now. ChatGPT and Bing aren't any help. I've rebuilt everything with static linkage and with shared libraries, checked all the compile options are compatible, and everything else AI can think of without success. Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_SCAN_FOR_MODULES)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(wxWidgets_CONFIG_EXECUTABLE /usr/local/bin/wx-config)
get_filename_component(PROJECT_ROOT ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
get_filename_component(PROJECT_NAME ${PROJECT_ROOT} NAME)
# Executable names
set(APP ${PROJECT_NAME})
# Project name
project(${APP} LANGUAGES CXX VERSION 0.1.0)
include_directories(
"${CMAKE_SOURCE_DIR}/src/include"
"${CMAKE_SOURCE_DIR}/src/modules"
"${VCPKG_PATH}/include"
"/usr/local/lib64/wx/include/gtk3-unicode-3.3"
)
# APP executable
add_executable(${APP}
src/app.cpp
src/frame.cpp
)
if(WIN32)
target_sources(${APP} PUBLIC
${APP}.rc)
endif(WIN32)
add_library(Modules)
target_sources(Modules PUBLIC FILE_SET CXX_MODULES FILES
src/modules/HSDebug.cpp
src/modules/HSUtil.cpp
)
find_package(wxWidgets REQUIRED COMPONENTS core base)
include("${wxWidgets_USE_FILE}")
target_link_libraries(${APP} PRIVATE ${wxWidgets_LIBRARIES})
target_link_libraries(Modules PRIVATE ${wxWidgets_LIBRARIES})
target_link_libraries(${APP} PRIVATE Modules)
Any ideas, peeps?
I've been stuck on this for about 5 days now.
These are hard to debug.
It looks like wxINT64_MIN
can have different definitions in include/wx/defs.h
:
#ifdef LLONG_MAX
#define wxINT64_MIN LLONG_MIN
...
#else
#define wxINT64_MIN (wxLL(-9223372036854775807)-1)
I suspect that when you compile the HSUtil.cpp
you take one branch, but when you compiled some other module earlier you took the other branch.
You can add #error This should not be used
to one branch (the one you think shouldn't be used) and compile everything without modules.
That build will probably fail due to the added #error
.
Now move the #error
to the other branch and try rebuilding everything again.
That will probably also fail, and now you have identified two sources which are using different definitions.
The #define LLONG_MIN ...
is probably coming from <limits.h>
, and one of your sources has #include <limits.h>
before #include <wx/defs.h>
, while the other source doesn't.