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

build system doesn't pick default LLVM libraries #148

Open
mbdevpl opened this issue Aug 28, 2019 · 6 comments
Open

build system doesn't pick default LLVM libraries #148

mbdevpl opened this issue Aug 28, 2019 · 6 comments

Comments

@mbdevpl
Copy link
Contributor

mbdevpl commented Aug 28, 2019

I'd like to report a build system issue(?) here. I'm not sure if this would be an issue according to the dev team, but I'd like to get your opinion on this if possible.

Expected behaviour: CastXML build uses the default clang libraries in the build.

Actual: it doesn't do that.

Details of what I observed are below:

I have few LLVMs in my system (6, 7, 8). However, the default is version 8.

$ llvm-config --version
8.0.0
$ clang --version
clang version 8.0.0-3 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Nevertheless, CastXML seems to insist on the version 6 installation, which on my system also happens to be incomplete. (I need version 6 only for some other legacy software, and no libclang-6.0-dev is installed because that legacy software doesn't need all of clang so I don't have it installed.)

In any case, the CastXML build chooses non-default LLVM, and breaks as expected:

$ cmake ../../Projects/CastXML/
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/lib/llvm-6.0/lib/cmake/clang/ClangTargets.cmake:496 (message):
  The imported target "clangBasic" references the file

     "/usr/lib/llvm-6.0/lib/libclangBasic.a"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/usr/lib/llvm-6.0/lib/cmake/clang/ClangTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/lib/cmake/clang-6.0/ClangConfig.cmake:19 (include)
  CMakeLists.txt:87 (find_package)


-- Configuring incomplete, errors occurred!
See also "~/Software/CastXML/CMakeFiles/CMakeOutput.log".

I wonder, why CastXML prefers 6 when my system prefers 8?

Fortunately, I still can force the version, as CastXML's readme states:

Clang_DIR
Location of the LLVM/Clang SDK. Set to /lib/cmake/clang, where is the top of the LLVM/Clang SDK install tree. Alternatively, LLVM_DIR may be set to /lib/cmake/llvm.

$ llvm-config --cmakedir
/usr/lib/llvm-8/lib/cmake/llvm
$ cmake ../../Projects/CastXML/ -DLLVM_DIR="$(llvm-config --cmakedir)"
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~/Software/CastXML
@bradking
Copy link
Member

CastXML uses find_package(Clang) here. Make sure you have the Clang 8 development package installed in addition to LLVM 8.

mbdevpl added a commit to mbdevpl/CastXML that referenced this issue Aug 29, 2019
@mbdevpl
Copy link
Contributor Author

mbdevpl commented Aug 29, 2019

The build works when I force LLVM 8 via the respective CMake config variable.

Actually, I have bunch of -dev packages installed:

$ apt list --installed "libclang*-dev"
Listing... Done
libclang-8-dev/disco,now 1:8-3 amd64 [installed,automatic]
libclang-common-6.0-dev/disco,now 1:6.0.1-11 amd64 [installed,automatic]
libclang-common-7-dev/disco,now 1:7.0.1-8 amd64 [installed,automatic]
libclang-common-8-dev/disco,now 1:8-3 amd64 [installed,automatic]
libclang-dev/disco,now 1:8.0-48~exp1ubuntu1 amd64 [installed]

But the only fully usable LLVM is version 8, which is how I want it to be.

The problem is maybe because I have more than one ClangConfig.cmake in my system:

$ find /usr -name "ClangConfig.cmake" 2>/dev/null
/usr/lib/llvm-8/lib/cmake/clang/ClangConfig.cmake
/usr/lib/llvm-6.0/lib/cmake/clang/ClangConfig.cmake
/usr/lib/llvm-7/lib/cmake/clang/ClangConfig.cmake

And those files don't even come from *-dev package:

$ apt-file find /usr/lib/llvm-6.0/lib/cmake/clang/ClangConfig.cmake
clang-6.0: /usr/lib/llvm-6.0/lib/cmake/clang/ClangConfig.cmake

From my brief search, the way CMake sorts results in case multiple candidates are found via find_package could be the culprit:

The default order for sorting packages found using find_package(). It can assume one of the following values:

NONE
Default. No attempt is done to sort packages. The first valid package found will be selected.
...

Therefore whatever is the "default system version" of LLVM is ignored by the CMake build, which picks one pretty much at random... So in other words, it looks like only keeping a single clang would help CMake to automatically use the correct LLVM version.

I experimented a bit and found that adding the below lines before find_package works in my case, as this way at least the latest, and not random version of LLVM seems to be used:

# If several LLVM versions provide CMake packages, try to use the latest one.
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)

Relevant documentation is here:

I created a commit with those changes at mbdevpl@adad560 - would it be desired/acceptable to submit pull request, or is this not something you'd like to see in CastXML?

@bradking
Copy link
Member

@mbdevpl yes, please open a PR with that change.

@mbdevpl
Copy link
Contributor Author

mbdevpl commented Aug 29, 2019

Opened #149.

bradking pushed a commit to mbdevpl/CastXML that referenced this issue Aug 29, 2019
bradking pushed a commit to mbdevpl/CastXML that referenced this issue Aug 29, 2019
@muhsag
Copy link

muhsag commented Jul 25, 2020

i ran into the same issue and after a bit of a research it worked for me. it turns out that i have multiple version of libclang

root@Kali:# apt list --installed "libclang*-dev"
Listing... Done
libclang-9-dev/kali-rolling,now 1:9.0.1-13 amd64 [installed,automatic]`
libclang-common-6.0-dev/kali-rolling,now 1:6.0.1-14.1 amd64 [installed,automatic]
libclang-common-8-dev/kali-rolling,now 1:8.0.1-9 amd64 [installed,automatic]
libclang-common-9-dev/kali-rolling,now 1:9.0.1-13 amd64 [installed,automatic]
libclang-dev/kali-rolling,now 1:9.0-49.1 amd64 [installed]

so i had to remove the oldest version which is 6.0

root@Kali:# sudo apt-get purge --auto-remove libclang-common-6.0-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  clang-6.0* libclang-common-6.0-dev* libclang1-6.0* libllvm6.0* llvm-6.0* llvm-6.0-dev* llvm-6.0-runtime*
0 upgraded, 0 newly installed, 7 to remove and 140 not upgraded.
After this operation, 359 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 495182 files and directories currently installed.)
Removing clang-6.0 (1:6.0.1-14.1) ...
Removing libclang-common-6.0-dev (1:6.0.1-14.1) ...
Removing libclang1-6.0 (1:6.0.1-14.1) ...
Removing llvm-6.0-dev (1:6.0.1-14.1) ...
Removing llvm-6.0 (1:6.0.1-14.1) ...
Removing llvm-6.0-runtime (1:6.0.1-14.1) ...
Removing libllvm6.0:amd64 (1:6.0.1-14.1) ...
Processing triggers for libc-bin (2.30-8) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for kali-menu (2020.3.2) ...

and finally ran cmake

root@Kali:# cmake ..
-- Found LLVM 9.0.1
-- Using LLVMConfig.cmake in: /usr/lib/llvm-9/lib/cmake/llvm
-- Using ClangConfig.cmake in: /usr/lib/llvm-9/lib/cmake/clang
/usr/bin/ar: creating t.a
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test CXX_SUPPORTS_CXX_STD
-- Performing Test CXX_SUPPORTS_CXX_STD - Success
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FDATA_SECTIONS
-- Performing Test C_SUPPORTS_FDATA_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success
CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:824 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_ENABLE_EH'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:825 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_ENABLE_RTTI'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:928 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_EXPORT_SYMBOLS_FOR_PLUGINS'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/

gmalecha pushed a commit to bedrocksystems/BRiCk that referenced this issue Aug 3, 2020
Without this change, make cpp2v results in
CMake Error at /usr/lib/llvm-7/lib/cmake/clang/ClangTargets.cmake:544 (message):
  The imported target "clangBasic" references the file

     "/usr/lib/llvm-7/lib/libclangBasic.a"

if llvm-7 is installed in addition to llvm-10.
See also CastXML/CastXML#148
@RoyZhang7
Copy link

i ran into the same issue and after a bit of a research it worked for me. it turns out that i have multiple version of libclang

root@Kali:# apt list --installed "libclang*-dev"
Listing... Done
libclang-9-dev/kali-rolling,now 1:9.0.1-13 amd64 [installed,automatic]`
libclang-common-6.0-dev/kali-rolling,now 1:6.0.1-14.1 amd64 [installed,automatic]
libclang-common-8-dev/kali-rolling,now 1:8.0.1-9 amd64 [installed,automatic]
libclang-common-9-dev/kali-rolling,now 1:9.0.1-13 amd64 [installed,automatic]
libclang-dev/kali-rolling,now 1:9.0-49.1 amd64 [installed]

so i had to remove the oldest version which is 6.0

root@Kali:# sudo apt-get purge --auto-remove libclang-common-6.0-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  clang-6.0* libclang-common-6.0-dev* libclang1-6.0* libllvm6.0* llvm-6.0* llvm-6.0-dev* llvm-6.0-runtime*
0 upgraded, 0 newly installed, 7 to remove and 140 not upgraded.
After this operation, 359 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 495182 files and directories currently installed.)
Removing clang-6.0 (1:6.0.1-14.1) ...
Removing libclang-common-6.0-dev (1:6.0.1-14.1) ...
Removing libclang1-6.0 (1:6.0.1-14.1) ...
Removing llvm-6.0-dev (1:6.0.1-14.1) ...
Removing llvm-6.0 (1:6.0.1-14.1) ...
Removing llvm-6.0-runtime (1:6.0.1-14.1) ...
Removing libllvm6.0:amd64 (1:6.0.1-14.1) ...
Processing triggers for libc-bin (2.30-8) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for kali-menu (2020.3.2) ...

and finally ran cmake

root@Kali:# cmake ..
-- Found LLVM 9.0.1
-- Using LLVMConfig.cmake in: /usr/lib/llvm-9/lib/cmake/llvm
-- Using ClangConfig.cmake in: /usr/lib/llvm-9/lib/cmake/clang
/usr/bin/ar: creating t.a
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test CXX_SUPPORTS_CXX_STD
-- Performing Test CXX_SUPPORTS_CXX_STD - Success
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FDATA_SECTIONS
-- Performing Test C_SUPPORTS_FDATA_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success
CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:824 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_ENABLE_EH'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:825 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_ENABLE_RTTI'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/lib/llvm-9/lib/cmake/llvm/HandleLLVMOptions.cmake:928 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'LLVM_EXPORT_SYMBOLS_FOR_PLUGINS'.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/

Had the same issue. I got confused after reading the PR comments (it makes total sense to me), then glad your method worked.
For whoever reaches here, the merged PR might not work if you have libclang6.0. Please follow quoted reply to remove it.

Maybe worth reopening issue?

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

4 participants