At the first glance, it’s coming with that c-index-test is just only containing c files (without cpp(cxx,c++) files).
So cmake recognize it as pure C project,
and so it’s link options that resident in link.txt is
/usr/bin/gcc CMakeFiles/c-index-test.dir/c-index-test.c.o -o …/…/…/…/bin/c-index-test -rdynamic …/…/…/…/lib/libCIndex.so …/…/…/…/lib/libclangIndex.a …/…/…/…/lib/libclangFrontend.a …/…/…/…/lib/libclangSema.a …/…/…/…/lib/libclangAST.a …/…/…/…/lib/libclangLex.a …/…/…/…/lib/libclangBasic.a …/…/…/…/lib/libLLVMBitReader.a …/…/…/…/lib/libLLVMMC.a …/…/…/…/lib/libLLVMCore.a …/…/…/…/lib/libLLVMSupport.a …/…/…/…/lib/libLLVMSystem.a -ldl -lpthread -Wl,-rpath,/home/dreamkxd/llvm/lib
And so, it’s won’t linkage with C++ library. So it’s failure to compiling the c-index-test project
Is there any solution to this problem?
You’re building using CMake? Try modifying tools/CIndex/CMakeLists.txt by adding the following command at the end:
set_target_properties(CIndex
PROPERTIES
LINKER_LANGUAGE CXX)
If that works for you, please tell me so I can commit the change to svn.
Yes, but I does’t modify the file tools/CIndex/CMakeLists.txt.
And I modify another file AddLLVM.cmake
And I think it’s get more meaning, because llvm is C++ application, so it’s must be using the std-c++ library(stl)
So need to linkage with C++,
By the way, I’ve already test, it’s working:)
At last, I get it working, And I refactoring the llvm cmake system.
I think did this should make cmake for more easy to diagnose, because we always facing all kinds of linking error around the development period, for the
reason of fast locate the error, i print out the link info(). Because of gcc is very dependent on the order of the library to linked,
So I changed the order for the link of dynamic library, also I removed the redundant function in LLVMConfig.cmake module
By the way, for the last success on building CIndex, we must apply these two patch simultaneous .
And I want to mention, if LLVM will support dynamic library linkage?
If that’s true, then we can modify the cmake system to support it:)
Thanks.
llvm-cmake-message-dependent.patch (2.68 KB)
clang-cmake-fix-CIndex-link-error-mingw.patch (854 Bytes)
Is there anyone get the time to apply this patch?
Is there anyone get the time to apply this patch?
I've committed my suggested fix. There's no point in setting the LINKER_LANGUAGE property of every LLVM library, because CMake figures out the right language based on the file extensions of the source files.
- Doug
I’ve committed my suggested fix. There’s no point in setting the LINKER_LANGUAGE property of every LLVM library, because CMake figures out the right language based on the file extensions of the source files.
Yes, CMake figures out the right language based on the file extensions of the source files.
But, llvm is based on C++
for example, if you create a application just containing C extension files,
but using llvm as the midware, then CMake system must auto recognize the LINKER_LANGUAGE as CXX, but not C. Even all source files in this project is C extension.
Now, it’s using a strange hack, just
set_target_properties(c-index-test
PROPERTIES
LINKER_LANGUAGE CXX)
It’s not reasonable, because it’s not because of c-index-test.c lead the
LINKER_LANGUAGE to be CXX
but llvm make this happened, so it’s shouldn’t be placed at
c-index-test.c/CMakeLists.txt
and should be placed at
AddLLVM.cmake
That’s means, every new project(OR executable) using LLVM as the dependent,
then then
LINKER_LANGUAGE must be set to CXX in an auto way,
but not set it manually.
I’ve committed my suggested fix. There’s no point in setting the LINKER_LANGUAGE property of every LLVM library, because CMake figures out the right language based on the file extensions of the source files.
Yes, CMake figures out the right language based on the file extensions of the source files.
But, llvm is based on C++
That does not mean that every library or application built within the LLVM tree must be linked as C++.
for example, if you create a application just containing C extension files,
but using llvm as the midware, then CMake system must auto recognize the LINKER_LANGUAGE as CXX, but not C. Even all source files in this project is C extension.
Now, it’s using a strange hack, just
set_target_properties(c-index-test
PROPERTIES
LINKER_LANGUAGE CXX)
It’s not reasonable, because it’s not because of c-index-test.c lead the
LINKER_LANGUAGE to be CXX
but llvm make this happened, so it’s shouldn’t be placed at
c-index-test.c/CMakeLists.txt
and should be placed at
AddLLVM.cmake
That’s means, every new project(OR executable) using LLVM as the dependent,
then then
LINKER_LANGUAGE must be set to CXX in an auto way,
but not set it manually.
There is only one place in the entire LLVM + Clang source tree where we need to explicitly set the linker language to C++. There is no point in trying to generalize when there is only one example, and we don’t know if the next target we add that has only .c files will require C++ linkage or not. If it does, we can decide to generalize then (or not).
Mmm, do you see that patch? Because the order of those linked library
is incorrect. Mingw can't generate libCindex.dll.
So I midified the likage order.
Also, for the reason of removing duplicated code, I removed some
unnecessay cmake code. And add an new cmake function