Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile glaze example because of the CMake error #1615

Open
hungptit opened this issue Feb 15, 2025 · 4 comments
Open

Cannot compile glaze example because of the CMake error #1615

hungptit opened this issue Feb 15, 2025 · 4 comments

Comments

@hungptit
Copy link

hungptit commented Feb 15, 2025

I could not compile Glaze's examples using CMake's FetchContent. Everything works perfectly when I remove the in-source check from the prelude.cmake file. What am I missing?

The error message

CMake Error at _deps/glaze-src/cmake/prelude.cmake:4 (message):
  In-source builds are not supported.  Please read the BUILDING document
  before trying to build this project.  You may need to delete
  'CMakeCache.txt' and 'CMakeFiles/' first.
Call Stack (most recent call first):
  _deps/glaze-src/CMakeLists.txt:3 (include)

My glaze.cmake file

include(FetchContent)

FetchContent_Declare(
  glaze
  GIT_REPOSITORY https://github.com/stephenberry/glaze.git
  GIT_TAG v4.4.2
  GIT_SHALLOW TRUE)

set(BUILD_TESTING OFF)
set(glaze_BUILD_EXAMPLES OFF)
set(glaze_DEVELOPER_MODE OFF)
set(glaze_ENABLE_FUZZING OFF)
set(glaze_ENABLE_AVX2 ON)

FetchContent_MakeAvailable(glaze)
@stephenberry
Copy link
Owner

If you want to build the tests/examples then the recommended approach is to clone Glaze and run CMake. By default Glaze doesn't build tests when including in another project. There is a glaze_BUILD_EXAMPLES CMake option. Did you try this?

@hungptit
Copy link
Author

Thank you for the quick response. I compile my examples outside the glaze source folder (using FetchContent). This is my CMakeLists.txt, and you can find the content of glaze.cmake in the first comment.

include(${PROJECT_SOURCE_DIR}/cmake/catch2.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/glaze.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/nanobench.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/boost.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/rapidjson.cmake)

# We cannot compile Glaze examples using clang++
set(CMAKE_CXX_COMPILER g++)

set(TEST_FILES glaze_test)
foreach(SRC_FILE ${TEST_FILES})
  add_executable(${SRC_FILE} ${SRC_FILE}.cpp)
  target_link_libraries(
    ${SRC_FILE} PRIVATE Catch2::Catch2WithMain fmt::fmt glaze::glaze nanobench
                        Boost::json utilities)
  target_include_directories(${SRC_FILE} PRIVATE ${rapidjson_SOURCE_DIR}/include
                                                 ${PROJECT_SOURCE_DIR})
  add_test(${SRC_FILE} ${SRC_FILE})
endforeach(SRC_FILE)

enable_testing()

@hungptit
Copy link
Author

I use g++ instead of clang++ (v19.1.7) to fix compilation failures.

In file included from /home/hungptit/working/experiments/glaze/glaze_test.cpp:12:
In file included from /home/hungptit/working/experiments/_deps/glaze-src/include/glaze/json/write.hpp:24:
In file included from /home/hungptit/working/experiments/_deps/glaze-src/include/glaze/core/reflect.hpp:7:
In file included from /home/hungptit/working/experiments/_deps/glaze-src/include/glaze/core/common.hpp:17:
In file included from /home/hungptit/working/experiments/_deps/glaze-src/include/glaze/core/meta.hpp:8:
/home/hungptit/working/experiments/_deps/glaze-src/include/glaze/reflection/get_name.hpp:27:19: error: variable 'glz::detail::external<(anonymous namespace)::my_struct>' is used but not defined in this translation unit, and cannot be defined in any other translation unit because its type does not have linkage
   27 |    extern const T external;
      |                   ^
/home/hungptit/working/experiments/_deps/glaze-src/include/glaze/reflection/get_name.hpp:48:71: note: used here
   48 |    constexpr std::string_view get_name_impl = mangled_name<get_ptr<N>(external<std::remove_volatile_t<T>>)>();
      |                                                                       ^
1 error generated.
make[2]: *** [glaze/CMakeFiles/glaze_test.dir/build.make:79: glaze/CMakeFiles/glaze_test.dir/glaze_test.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4033: glaze/CMakeFiles/glaze_test.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

@stephenberry
Copy link
Owner

Clang requires the flag -stdlib=libc++ to build Glaze on Linux because of compiler bugs. But, it is tested on Clang 17, 18, and 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants