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

compilation and installation #241

Closed
lzx1995 opened this issue May 17, 2024 · 9 comments
Closed

compilation and installation #241

lzx1995 opened this issue May 17, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@lzx1995
Copy link

lzx1995 commented May 17, 2024

My system is RedHat 7, and I executed the following commands to install opencilk:

 git clone -b opencilk/v1.1 https://github.com/OpenCilk/infrastructure
infrastructure/tools/get $(pwd)/opencilk
infrastructure/tools/build $(pwd)/opencilk $(pwd)/opencilk/build

When I executed the last command, it threw an error indicating that my gcc version is 4.8.5, while the minimum required is 5.1. I'm not quite sure what went wrong. I have loaded gcc 10.3.0 using the module, perhaps the gcc used here is referenced by an absolute path? I set the absolute path of gcc in opencilk/llvm/CMakeLists.txt:

set(GCC_PATH "/gpfs/software/gcc/10.3.0/bin/gcc")
set(GPP_PATH "/gpfs/software/gcc/10.3.0/bin/g++")
set(CMAKE_C_COMPILER ${GCC_PATH})
set(CMAKE_CXX_COMPILER ${GPP_PATH})

Then I executed the last command again, this time without error about the gcc version being too low. However, another problem occurred. Below is the error message:

[100%] Built target clang_rt.cilksan-x86_64
[100%] Built target cilksan
[100%] Built target cilktools
[100%] No install step for 'runtimes'
[100%] Completed 'runtimes'
[100%] Built target runtimes
+ case "${OS}" in
++ xxx/opencilk/build/bin/clang -print-target-triple
+ TRIPLE=x86_64-unknown-linux-gnu
+ LIBNAME=libopencilk.a
++ sed -n '/set.LLVM_VERSION_MAJOR/s/^.* \([0-9.]*\))/\1/p' xxx/opencilk/llvm/CMakeLists.txt
+ VERSION=12
+ LIBPATH=xxx/opencilk/build/lib/clang/12/lib/x86_64-unknown-linux-gnu/libopencilk.a
+ test -f xxx/opencilk/build/lib/clang/12/lib/x86_64-unknown-linux-gnu/libopencilk.a
+ echo 'Cheetah runtime library not found at xxx/opencilk/build/lib/clang/12/lib/x86_64-unknown-linux-gnu/libopencilk.a'
Cheetah runtime library not found at xxx/opencilk/build/lib/clang/12/lib/x86_64-unknown-linux-gnu/libopencilk.a
+ exit 1

I'm wondering how to solve this issue?

@lzx1995 lzx1995 added the bug Something isn't working label May 17, 2024
@neboat
Copy link
Collaborator

neboat commented May 17, 2024

Thanks for reaching out.

Can you check whether there is a copy of libopencilk.a anywhere in the build directory, and if so, tell me where it is? The following command should do the trick, where the first argument to find should be the path to the opencilk build directory:

find xxx/opencilk/build/ -name "libopencilk.a"

It also seems that you're using a pretty old version of OpenCilk. The latest version is OpenCilk 2.1. Is there a reason why you're using an older version?

@lzx1995
Copy link
Author

lzx1995 commented May 17, 2024

Thanks for reaching out.

Can you check whether there is a copy of libopencilk.a anywhere in the build directory, and if so, tell me where it is? The following command should do the trick, where the first argument to find should be the path to the opencilk build directory:

find xxx/opencilk/build/ -name "libopencilk.a"

It also seems that you're using a pretty old version of OpenCilk. The latest version is OpenCilk 2.1. Is there a reason why you're using an older version?

I used the command find xxx/opencilk/build/ -name "libopencilk.a" to locate libopencilk.a, and here is its location:

xxx/opencilk/build/lib/clang/12.0.0/lib/x86_64-unknown-linux-gnu/libopencilk.a

I made the following modifications in infrastructures/tool/build:

#VERSION=$(sed -n '/set.PACKAGE_VERSION/s/^.* \([0-9.]*\))/\1/p' "${CHEETAH_SOURCE}/CMakeLists.txt")
VERSION="12.0.0"

Then I rebuilt, and the aforementioned error was resolved, so perhaps there is an issue with the VERSION line of code? However, there's a new issue now. When I compile a helloWorld program using clang++, it compiles successfully. But when I try to compile a program with a new header file that uses C++17, it says it can't find that header file. Below is a simple CPP code that fails to compile:

#include <optional>

int main() {
        auto a = 0;
        return 0;
}

I compile using the following command:

clang++ -std=c++17   option.cpp -o option

The error message is:

option.cpp:1:10: fatal error: 'optional' file not found
#include <optional>

Is this because certain files weren't linked during compilation?

It also seems that you're using a pretty old version of OpenCilk. The latest version is OpenCilk 2.1. Is there a reason why you're using an older version?
"I'm encountering compilation issues when trying to compile the code for a research paper I'm studying, which requires Opencilk 1.1. Unfortunately, I'm using Opencilk 2.1 and cannot compile successfully."

@neboat
Copy link
Collaborator

neboat commented May 17, 2024

I used the command find xxx/opencilk/build/ -name "libopencilk.a" to locate libopencilk.a, and here is its location:

xxx/opencilk/build/lib/clang/12.0.0/lib/x86_64-unknown-linux-gnu/libopencilk.a

I made the following modifications in infrastructures/tool/build:

#VERSION=$(sed -n '/set.PACKAGE_VERSION/s/^.* \([0-9.]*\))/\1/p' "${CHEETAH_SOURCE}/CMakeLists.txt")
VERSION="12.0.0"

Then I rebuilt, and the aforementioned error was resolved, so perhaps there is an issue with the VERSION line of code? However, there's a new issue now. When I compile a helloWorld program using clang++, it compiles successfully. But when I try to compile a program with a new header file that uses C++17, it says it can't find that header file. Below is a simple CPP code that fails to compile:

#include <optional>

int main() {
        auto a = 0;
        return 0;
}

I compile using the following command:

clang++ -std=c++17   option.cpp -o option

The error message is:

option.cpp:1:10: fatal error: 'optional' file not found
#include <optional>

Is this because certain files weren't linked during compilation?

On Linux, clang uses the libraries and headers from a GCC installation it finds on the system. Because it sounds like you have multiple installations of GCC on your system, including an an installation of GCC 4.8, I suspect that clang is finding the GCC 4.8 installation, which doesn't fully support C++17. As a result, it fails to find the optional header file and throws the error you're getting.

To confirm this, can you share the verbose output of your clang compile command, that is, the output of this command:

clang++ -std=c++17   option.cpp -o option -v

The verbose output will include a list of GCC installations clang finds and a message about which GCC installation clang chooses to use.

Clang supports the --gcc-toolchain=<dir> compiler flag to specify the GCC installation to use. In principle, you can use that flag to tell clang to use the GCC 10.3 installation available to you. It can be tricky, though, to get the argument to --gcc-toolchain right.

Can you search inside /gpfs/software/gcc/10.3.0/ for optional, to see if you can find that header file in there? The following command should work:

find /gpfs/software/gcc/10.3.0/ --name "optional"

Hopefully, you will find the optional header file somewhere in there under a subdirectory structure that looks like <prefix>/lib/gcc/<triple>/<version>. If so, then I think you can specify --gcc-toolchain=<prefix> to the clang compile command to get it to compile.

There are some other options we can try if that doesn't work, but they may be more complicated. Let's try searching the GCC 10.3 installation first.

It also seems that you're using a pretty old version of OpenCilk. The latest version is OpenCilk 2.1. Is there a reason why you're using an older version?
"I'm encountering compilation issues when trying to compile the code for a research paper I'm studying, which requires Opencilk 1.1. Unfortunately, I'm using Opencilk 2.1 and cannot compile successfully."

Got it, thanks. If you have a chance, can you tell me what fails when trying to compile with OpenCilk 2.1?

@lzx1995
Copy link
Author

lzx1995 commented May 17, 2024

I used the command find xxx/opencilk/build/ -name "libopencilk.a" to locate libopencilk.a, and here is its location:

xxx/opencilk/build/lib/clang/12.0.0/lib/x86_64-unknown-linux-gnu/libopencilk.a

I made the following modifications in infrastructures/tool/build:

#VERSION=$(sed -n '/set.PACKAGE_VERSION/s/^.* \([0-9.]*\))/\1/p' "${CHEETAH_SOURCE}/CMakeLists.txt")
VERSION="12.0.0"

Then I rebuilt, and the aforementioned error was resolved, so perhaps there is an issue with the VERSION line of code? However, there's a new issue now. When I compile a helloWorld program using clang++, it compiles successfully. But when I try to compile a program with a new header file that uses C++17, it says it can't find that header file. Below is a simple CPP code that fails to compile:

#include <optional>

int main() {
        auto a = 0;
        return 0;
}

I compile using the following command:

clang++ -std=c++17   option.cpp -o option

The error message is:

option.cpp:1:10: fatal error: 'optional' file not found
#include <optional>

Is this because certain files weren't linked during compilation?

On Linux, clang uses the libraries and headers from a GCC installation it finds on the system. Because it sounds like you have multiple installations of GCC on your system, including an an installation of GCC 4.8, I suspect that clang is finding the GCC 4.8 installation, which doesn't fully support C++17. As a result, it fails to find the optional header file and throws the error you're getting.

To confirm this, can you share the verbose output of your clang compile command, that is, the output of this command:

clang++ -std=c++17   option.cpp -o option -v

The verbose output will include a list of GCC installations clang finds and a message about which GCC installation clang chooses to use.

Clang supports the --gcc-toolchain=<dir> compiler flag to specify the GCC installation to use. In principle, you can use that flag to tell clang to use the GCC 10.3 installation available to you. It can be tricky, though, to get the argument to --gcc-toolchain right.

Can you search inside /gpfs/software/gcc/10.3.0/ for optional, to see if you can find that header file in there? The following command should work:

find /gpfs/software/gcc/10.3.0/ --name "optional"

Hopefully, you will find the optional header file somewhere in there under a subdirectory structure that looks like <prefix>/lib/gcc/<triple>/<version>. If so, then I think you can specify --gcc-toolchain=<prefix> to the clang compile command to get it to compile.

There are some other options we can try if that doesn't work, but they may be more complicated. Let's try searching the GCC 10.3 installation first.

It also seems that you're using a pretty old version of OpenCilk. The latest version is OpenCilk 2.1. Is there a reason why you're using an older version?
"I'm encountering compilation issues when trying to compile the code for a research paper I'm studying, which requires Opencilk 1.1. Unfortunately, I'm using Opencilk 2.1 and cannot compile successfully."

I executed the following command:

clang++ -std=c++17   option.cpp -o option -v

The following is part of the output:

Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gpfs/home/lizhixiong1/opencilk/build/bin
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5

It seems that it indeed chose an older version of GCC. After I specified --gcc-toolchain pointing to GCC 10.3.0, it reported some strange errors like error: use of undeclared identifier 'std'. Could it be that after specifying --gcc-toolchain, I need to manually link some libraries? I now want to recompile OpenCilk 1.1. Where should I specify the location of GCC? It seems that specifying the GCC location in the opencilk/llvm/CMakeLists.txt file only allows it to pass the GCC version check, but it actually uses GCC 4.8?

Got it, thanks. If you have a chance, can you tell me what fails when trying to compile with OpenCilk 2.1?

The API of OpenCilk 2.1 seems to have subtle differences from the API of 1.1. This has caused the code provided in the paper to fail to compile. On another computer with Ubuntu 18, I can successfully compile the code using OpenCilk 1.1.

@neboat
Copy link
Collaborator

neboat commented May 17, 2024

It seems that it indeed chose an older version of GCC. After I specified --gcc-toolchain pointing to GCC 10.3.0, it reported some strange errors like error: use of undeclared identifier 'std'. Could it be that after specifying --gcc-toolchain, I need to manually link some libraries?

The errors you saw when you specified --gcc-toolchain suggest to me that the path you provided does not correspond to a valid installation of GCC. Specifically, it sounds like clang was not able to find C/C++ headers and libraries in the expected directory structure under the path passed to --gcc-toolchain.

Can you share the full clang++ command you ran where you added --gcc-toolchain argument, as well as the verbose output of that command, that is, where you pass both --gcc-toolchain=<dir> and -v?

I now want to recompile OpenCilk 1.1. Where should I specify the location of GCC? It seems that specifying the GCC location in the opencilk/llvm/CMakeLists.txt file only allows it to pass the GCC version check, but it actually uses GCC 4.8?

For that version of OpenCilk, you should be able specify the to CMake the flag -DGCC_INSTALL_PREFIX=<path/to/gcc/install/prefix>. Because you're using the build script in the infrastructure repo, you can add that CMake flag here: https://github.com/OpenCilk/infrastructure/blob/opencilk/v1.1/tools/build#L102-L107. Note that the path you provide to -DGCC_INSTALL_PREFIX should include the subdirectories bin, lib, include, and so on.

Edit: Alternatively, if you're rebuilding OpenCilk, you might try building OpenCilk with its own copies of the C++ standard headers and libraries. To do that, modify this line in the build script as follows:

- : "${COMPILER_RT_COMPONENTS:=";compiler-rt"}" ;;
+ : "${COMPILER_RT_COMPONENTS:=";compiler-rt;libcxx;libcxxabi"}" ;;

Those custom-built C++ standard headers and libraries won't be the same as those in your copy of GCC 10.3, but they might suffice for what you're trying to do.

@fuyj19
Copy link

fuyj19 commented May 17, 2024

Got it, thanks. If you have a chance, can you tell me what fails when trying to compile with OpenCilk 2.1?

Firstly, use OpenCilk2.1 to compile our project and encounter an error

include/parallel.h:8:10: fatal error: 'cilk/reducer_opadd.h' file not found
#include <cilk/reducer_opadd.h>

Then locate reducer_opadd.h found that this header file just can be found in /opt/opencilk-1.1/lib/clang/12.0.0/include/cilk/reducer_opadd.h
So change to OpenCilk1.1, luckily compile it again success.

Mentionally, Clang supports the --gcc-toolchain=<dir>should As of Clang-16 maybe? because try this encounter an error:

clang++ --gcc-install-dir=/gpfs/software/gcc/10.3.0/ testclang.cpp -o testclang -v
clang-12:error:unsupported option'--gcc-install-dir=/gpfs/software/gcc/10.3.0/clang version 12.0.0 (https://github.com/0pencilk/opencilk-project 5d2851d7d0e689ecb3b893aa6abd12390b838c4b)
Target:x86 64-unknown-linux-gnu
Thread model: posix
InstalledDir:/gpfs/home/lizhixiong1/opencilk/build/bin
Found candidate Gcc installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate Gcc installation:/usr/lib/gcc/i686-redhat-linux/4.8.5
Found candidate Gcc installation:/usr/lib/gcc/x86 64-redhat-linux/4.8.2
Found candidate Gcc installation: /usr/lib/gcc/x86 64-redhat-linux/4.8.5
Selected Gcc installation: /usr/lib/gcc/x86 64-redhat-linux/4.8.5
...

about this we found this https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 may be useful.

@neboat
Copy link
Collaborator

neboat commented May 17, 2024

Got it, thanks. If you have a chance, can you tell me what fails when trying to compile with OpenCilk 2.1?

Firstly, use OpenCilk2.1 to compile our project and encounter an error

include/parallel.h:8:10: fatal error: 'cilk/reducer_opadd.h' file not found
#include <cilk/reducer_opadd.h>

Then locate reducer_opadd.h found that this header file just can be found in /opt/opencilk-1.1/lib/clang/12.0.0/include/cilk/reducer_opadd.h So change to OpenCilk1.1, luckily compile it again success.

Yes, OpenCilk 2.1 has a revamped implementation of reducers, and the cilk/reducer_opadd.h header has been replaced. For "opadd" reducers, there is a new header file, cilk/opadd_reducer.h, that provides a similar interface. It's not a drop-in replacement the previous header, but the code change to the Cilk application code in question should be small.

If you would like to try that new header in OpenCilk 2.1, the code change looks something like this. Wherever the program uses an opadd reducer r, such as:

cilk::reducer<cilk::op_add<int>> r;

the declaration for the reducer r now looks like:

cilk::opadd_reducer<int> r;

If you want to give that a try, let me know how it goes. I'm happy to help you resolve any issues you encounter with the new reducers.

Mentionally, Clang supports the --gcc-toolchain=

should As of Clang-16 maybe? because try this encounter an error:

clang++ --gcc-install-dir=/gpfs/software/gcc/10.3.0/ testclang.cpp -o testclang -v
clang-12:error:unsupported option'--gcc-install-dir=/gpfs/software/gcc/10.3.0/clang version 12.0.0 (https://github.com/0pencilk/opencilk-project 5d2851d7d0e689ecb3b893aa6abd12390b838c4b)
Target:x86 64-unknown-linux-gnu
Thread model: posix
InstalledDir:/gpfs/home/lizhixiong1/opencilk/build/bin
Found candidate Gcc installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate Gcc installation:/usr/lib/gcc/i686-redhat-linux/4.8.5
Found candidate Gcc installation:/usr/lib/gcc/x86 64-redhat-linux/4.8.2
Found candidate Gcc installation: /usr/lib/gcc/x86 64-redhat-linux/4.8.5
Selected Gcc installation: /usr/lib/gcc/x86 64-redhat-linux/4.8.5
...

about this we found this https://discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091 may be useful.

OpenCilk 1.1 is based on Clang 12, so it won't support the newer --gcc-install-dir=<dir> option. So if you're using OpenCilk 1.1, you're stuck with either the --gcc-toolchain=<dir> option instead or the GCC_INSTALL_PREFIX CMake flag (when building OpenCilk from source).

@lzx1995
Copy link
Author

lzx1995 commented May 18, 2024

I specified the GCC location in the infrastructure/tool/build file and recompiled OpenCilk. Then I used the command clang++ -std=c++17 option.cpp -o option to compile option.cpp, and it compiled successfully. Here are the modifications I made:

+ : GCC_PREFIX=/gpfs/software/gcc/10.3.0
cmake -DLLVM_ENABLE_PROJECTS="${COMPONENTS}" \
      -DLLVM_ENABLE_RUNTIMES="${RUNTIMES}" \
      -DLLVM_TARGETS_TO_BUILD=host \
      -DLLVM_ENABLE_ASSERTIONS="${OPENCILK_ASSERTIONS:?}" \
      -DCMAKE_BUILD_TYPE="${OPENCILK_RELEASE:?}" \
+ :      -DCMAKE_C_COMPILER=${GCC_PREFIX}/bin/gcc \
+ :     -DCMAKE_CXX_COMPILER=${GCC_PREFIX}/bin/g++ \
+ :     -DGCC_INSTALL_PREFIX=${GCC_PREFIX} \
      "${OPENCILK_SOURCE}/llvm"

I saw here https://stackoverflow.com/questions/47734094/build-clang-from-source-using-specific-gcc-toolchain that this is an equivalent operation to --gcc-toolchain=<dir> . The reason I couldn't compile option.cpp using --gcc-toolchain=<dir> before might be because I forgot to add -std=c++17 . Anyway, the issue is now resolved. Many thanks to @neboat and @fyj19.

@neboat
Copy link
Collaborator

neboat commented May 20, 2024

Glad to hear you resolved the issue. Please reach out if you have any more questions or run into any other issues.

@neboat neboat closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants