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

Building on WSL Ubuntu 20.04 - Could use compiler and clang-config detection. #8

Open
mibli opened this issue May 12, 2022 · 1 comment

Comments

@mibli
Copy link

mibli commented May 12, 2022

First off, thanks for Your contribution to the society. This application is incredible and I'm already thinking of a way of integrating it into my development flow!

When building, first I have to specify CMAKE_CXX_COMPILER, which is already odd. Release is important otherwise it seems more dependencies are required.. Then I encounter error with strip, which is caused by empty ${LLVM_LIBRARIES} etc, which are pulled from clang-config.

$ cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DCMAKE_BUILD_TYPE=Release
-- Module support is disabled.
-- Version: 8.1.2
-- Build type: Release
-- CXX_STANDARD: 17
-- Required features: cxx_variadic_templates
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Found LLVM 12.0.0


-- Using LLVMConfig.cmake in: /usr/lib/llvm-12/cmake
CMake Error at CMakeLists.txt:73 (string):
  string sub-command STRIP requires two arguments.


CMake Error at CMakeLists.txt:78 (string):
  string sub-command STRIP requires two arguments.


CMake Error at CMakeLists.txt:83 (string):
  string sub-command STRIP requires two arguments.


-- Configuring incomplete, errors occurred!
See also "/mnt/c/r/fccf/.build/CMakeFiles/CMakeOutput.log".
See also "/mnt/c/r/fccf/.build/CMakeFiles/CMakeError.log".

In my system I'm using llvm12, so default clang-config (old one), shouldn't be used (and is not present in the system), perhaps it should be configurable and CMakeLists.txt shoud check whether it exists and is executable. I've solved this by modifying the CMakeLists.txt.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1156a5c..4ed1f14 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,17 +68,17 @@ add_definitions(${LLVM_DEFINITIONS})
 add_definitions(${CLANG_DEFINITIONS})

 # LLVM link libraries
-execute_process(COMMAND llvm-config --libs all
+execute_process(COMMAND llvm-config-12 --libs all
   OUTPUT_VARIABLE LLVM_LIBRARIES)
 string(STRIP ${LLVM_LIBRARIES} LLVM_LIBRARIES)

 # LLVM LD flags
-execute_process(COMMAND llvm-config --ldflags
+execute_process(COMMAND llvm-config-12 --ldflags
   OUTPUT_VARIABLE LLVM_LDFLAGS)
 string(STRIP ${LLVM_LDFLAGS} LLVM_LDFLAGS)

 # LLVM CXX FLAGS
-execute_process(COMMAND llvm-config --cxxflags
+execute_process(COMMAND llvm-config-12 --cxxflags
   OUTPUT_VARIABLE LLVM_CXXFLAGS)
 string(STRIP ${LLVM_CXXFLAGS} LLVM_CXXFLAGS)

Then the build fails on #include <clang-c/Index.h>, which doesn't seem to be present in my system (find /usr -iname 'Index.h' and find /usr -ipath '*/clang-c' returns nothing.).

PS. After some time I've figured that libclang-12-dev was missing.

$ cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DCMAKE_BUILD_TYPE=Release
-- Module support is disabled.
-- Version: 8.1.2
-- Build type: Release
-- CXX_STANDARD: 17
-- Required features: cxx_variadic_templates
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Found LLVM 12.0.0
-- Using LLVMConfig.cmake in: /usr/lib/llvm-12/cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/r/fccf/.build
$ make
Scanning dependencies of target fmt
[ 11%] Building CXX object _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o
[ 22%] Building CXX object _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o
[ 33%] Linking CXX static library libfmt.a
[ 33%] Built target fmt
Scanning dependencies of target fccf_lib
[ 44%] Building CXX object CMakeFiles/fccf_lib.dir/source/searcher.cpp.o
/mnt/c/r/fccf/source/searcher.cpp:8:10: fatal error: 'clang-c/Index.h' file not found
#include <clang-c/Index.h>  // This is libclang.
         ^~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/fccf_lib.dir/build.make:63: CMakeFiles/fccf_lib.dir/source/searcher.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:150: CMakeFiles/fccf_lib.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

So coming from this, I do think that compiler could be detected automatically. Also clang-config should be at least tested and settable using something like -DLLVM_CONFIG=/usr/bin/llvm-config-12.
In total I've installed libclang-12-dev libclang-cpp12-dev llvm-12-dev zlib1g.

@nerdneilsfield
Copy link

same error here.

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