Can't build with Clion
deadlocklogic opened this issue · 10 comments
Hi, great library!
I was able to build the lib with visual studio but no luck with Clion (using MSVC toolchain).
I even used set(LIBCLANG_LIBRARY C:/Program Files/LLVM/lib)
as recommended.
I am getting all sorts of linking errors (a short snippet):
cppast.lib(enum_parser.cpp.obj) : error LNK2001: unresolved external symbol __imp__clang_getCString
cppast.lib(variable_parser.cpp.obj) : error LNK2001: unresolved external symbol __imp__clang_getCString
cppast.lib(friend_parser.cpp.obj) : error LNK2001: unresolved external symbol __imp__clang_getCString
cppast.lib(function_parser.cpp.obj) : error LNK2001: unresolved external symbol __imp__clang_getCString
...
I am using a minimal setup with add_subdirectory
and target_link_libraries
.
Any suggestions?
Can you post your complete cmake invocation (e.g. cmake -D... /path/to/src
) and full output?
No, actually I let Clion load the CMake project for me.
My project hierarchy:
Project
src
CMakeLists.txt // Main CMakeLists
main.cpp
thirdparty
CMakeLists.txt // contains only the command add_subdirectory("cppast")
cppast // the git repo
CMakeLists.txt // Project CMakeLists
My Project CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project ("Test")
add_subdirectory ("source")
add_subdirectory ("thirdparty")
My Main CMakeLists.txt
add_executable(Test
"main.cpp"
)
target_include_directories(Test
PUBLIC
""
)
target_link_libraries(Test
PUBLIC
cppast
)
The following should work:
- set
LLVM_VERSION_EXPLICIT
to the full version of LLVM you have installed. - set
LIBCLANG_LIBRARY
to the path of thelibclang
library. - set
LIBCLANG_INCLUDE_DIR
to the libclang header files. - set
CLANG_BINARY
to the path of theclang++
executable.
I tried this with no luck:
set(LLVM_VERSION_EXPLICIT 13.0.0)
set(LIBCLANG_LIBRARY C:/Program Files/LLVM/lib/)
set(LIBCLANG_INCLUDE_DIR to C:/Program Files/LLVM/lib/clang/13.0.0/include/)
set(CLANG_BINARY C:/Program Files/LLVM/bin)
I tried this with no luck:
set(LLVM_VERSION_EXPLICIT 13.0.0) set(LIBCLANG_LIBRARY C:/Program Files/LLVM/lib/) set(LIBCLANG_INCLUDE_DIR to C:/Program Files/LLVM/lib/clang/13.0.0/include/) set(CLANG_BINARY C:/Program Files/LLVM/bin)
Can you post the CMake output?
Sorry for late reply.
This is a minimal repo
This is the log message I get when CMake loads the project:
"C:\Program Files\JetBrains\CLion 2021.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" C:\Users\User\CLionProjects\cppastTest
-- Fetching type_safe
-- Using vendored debug_assert
-- arithmetic_policy_default is undefined_behavior_arithmetic
-- Using LLVM version 11.0.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/User/CLionProjects/cppastTest/cmake-build-debug-visual-studio
Cannot get compiler information:
Compiler exited with error code 2: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx86\x86\cl.exe" @C:\Users\User\AppData\Local\Temp\response-file14709231634159687078 C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771 | @response-file14709231634159687078=/TP -D/D_CRT_SECURE_NO_WARNINGS /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /Be /Bd /EP
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
all:
@cd C:\Users\User\CLionProjects\cppastTest\cmake-build-debug-visual-studio\thirdparty\cppast\external\tpl
@set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt
@set LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\lib\x86;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86
@set CL=
@set _CL_=
@set LINK=
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx86\x86\cl.exe @<< C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771
/TP -D/D_CRT_SECURE_NO_WARNINGS /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /Be /Bd /EP<<
cl /TP -D/D_CRT_SECURE_NO_WARNINGS /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++17 /Be /Bd /EP
compiler-file7579352665388887771
ENC_CWD=C:\Users\User\CLionProjects\cppastTest\cmake-build-debug-visual-studio\thirdparty\cppast\external\tpl
ENC_CL=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx86\x86\cl.exe
ENC_SRC=C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771
ENC_PDB=C:\Users\User\CLionProjects\cppastTest\cmake-build-debug-visual-studio\thirdparty\cppast\external\tpl\vc140.pdb
ENC_CMD=-TP -D/D_CRT_SECURE_NO_WARNINGS -DWIN32 -D_WINDOWS -GR -EHs -EHc -Zi -Ob0 -Od -RTC1 -MDd -std:c++17 -Bd -EP -I"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\include" -I"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include" -I"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" -X
`C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx86\x86\c1xx.dll -zm0x0042B1C0 -il C:\Users\User\AppData\Local\Temp\_CL_0c97b66e -typedil -f C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771 -W 1 -Ze -D_MSC_EXTENSIONS -Zp8 -Gs -Focompiler-file7579352665388887771.obj -pc \:/ -Fdvc140.pdb -D_MSC_VER=1928 -D_MSC_FULL_VER=192829913 -D_MSC_BUILD=0 -D_WIN32 -D_M_IX86=600 -D_M_IX86_FP=2 -GS -Zc:forScope -Zc:wchar_t -D/D_CRT_SECURE_NO_WARNINGS -DWIN32 -D_WINDOWS -GR -D_CPPRTTI -EHs -D_CPPUNWIND -EHc -Zi -Ot -D__MSVC_RUNTIME_CHECKS -RTCs -RTCu -MDd -D_DEBUG -D_MT -D_DLL -std:c++17 -Bd -E -EP -I C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\include -I C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include -I C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -I C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt -I C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -I C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -I C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -I C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt'
C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771(173): error C2003: expected 'defined id'
C:\Users\User\AppData\Local\Temp\compiler-file7579352665388887771(173): error C2124: divide or mod by zero
[Failed to reload]
Using the following has no effect:
set(LLVM_VERSION_EXPLICIT 13.0.0)
set(LIBCLANG_LIBRARY C:/Program Files/LLVM/lib/)
set(LIBCLANG_INCLUDE_DIR to C:/Program Files/LLVM/lib/clang/13.0.0/include/)
set(CLANG_BINARY C:/Program Files/LLVM/bin)
By the way I am working on creating bindings of cppast
to scripting languages (lua ✅, python ❓ maybe).
So far I had few difficulties, mainly with the private virtual methods like in the code_generator.hpp
, is there any reason not making them protected and follow conventional OOP paradigms? Because I couldn't find a way around this issue other than making them protected
myself and diverge from the current implementation.
Extensive use of templates was also one, but with few external tweaks/patches I got around it (of course this lib was written for C++ and maybe with no plans to port/bind to other languages at first).
Sorry for the late reply. Looking at your CMake error message, this doesn't seem to be an issue with cppast but your setup in general. I can't really help you there, so I'm closing the issue.
So far I had few difficulties, mainly with the private virtual methods like in the code_generator.hpp, is there any reason not making them protected and follow conventional OOP paradigms?
Nobody except the code_generator
should be able to call them, so they're private.
of course this lib was written for C++ and maybe with no plans to port/bind to other languages at first
Yes. I think it's best to provide bindings for the clang API directly. cppast is mainly a workaround around libclang for situations where you can't use clang's C++ API. Adding another indirection on top doesn't seem to be a good idea when you can instead create bindings for the original API directly.