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 failure with clang 6 or 7 #350

Closed
joelagnel opened this issue Jan 15, 2019 · 4 comments
Closed

Compilation failure with clang 6 or 7 #350

joelagnel opened this issue Jan 15, 2019 · 4 comments
Labels
bug Something isn't working build Issues or PRs related to bpftrace building

Comments

@joelagnel
Copy link

Hi, I am attempting to build inside a debian chroot on Android.

I get the following build errors when compiling bpftrace with clang:

error: invalid argument '-std=c++14' not allowed with 'C'
make[2]: *** [resources/CMakeFiles/resources.dir/build.make:63: resources/CMakeFiles/resources.dir/headers.c.o] Error 1

My cmake command looks like

mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-7 -DCMAKE_CXX_COMPILER=clang++-7 ..

BCC itself builds and works fine with the same clang. Its bpftrace failing to build.

This seems similar to: #159 . Any thoughts @brendangregg ?

@mmarchini mmarchini added bug Something isn't working build Issues or PRs related to bpftrace building labels Jan 15, 2019
@mmarchini
Copy link
Contributor

Not related to #159 because here compiler is complaining that we are using -std=c++14 when building a .c file (more specifically, the resources/headers.c file generated by resources/CMakeList.txt). GCC only warn about this and ignores the parameter.

I'll send a PR to fix this shortly.

mmarchini added a commit to mmarchini/bpftrace that referenced this issue Jan 15, 2019
If we use clang to build bpftrace instead of GCC, it will complain about
trying to use the `-std-c++14` flag to comile headers.c. If we force
cmake to skip this flag on `.c` files, clang is not able to link
libresources.a correctly.

This patch changes the resources workflow to generate a .cpp file
instead, and to have a `src/headers.h` with all headers we currently
use. With this approach we get a safer linkage because the same
definition for the header strings is being used in clang_parser.cpp and
in headers.cpp.

Fixes: bpftrace#350
mmarchini added a commit to mmarchini/bpftrace that referenced this issue Jan 16, 2019
If we use clang to build bpftrace instead of GCC, it will complain about
trying to use the `-std-c++14` flag to comile headers.c. If we force
cmake to skip this flag on `.c` files, clang is not able to link
libresources.a correctly.

This patch changes the resources workflow to generate a .cpp file
instead, and to have a `src/headers.h` with all headers we currently
use. With this approach we get a safer linkage because the same
definition for the header strings is being used in clang_parser.cpp and
in headers.cpp.

Fixes: bpftrace#350
@joelagnel
Copy link
Author

Thanks a lot @mmarchini , I verified that this fixes the build.

mmarchini added a commit that referenced this issue Jan 16, 2019
If we use clang to build bpftrace instead of GCC, it will complain about
trying to use the `-std-c++14` flag to comile headers.c. If we force
cmake to skip this flag on `.c` files, clang is not able to link
libresources.a correctly.

This patch changes the resources workflow to generate a .cpp file
instead, and to have a `src/headers.h` with all headers we currently
use. With this approach we get a safer linkage because the same
definition for the header strings is being used in clang_parser.cpp and
in headers.cpp.

Fixes: #350
@asutherland
Copy link

I think this may have been regressed by 69cbd85 which introduced a simple_struct.c. I just tried to build from a fresh checkout and got the following error while running make:

error: invalid argument '-std=c++14' not allowed with 'C'
tests/CMakeFiles/simple_struct.dir/build.make:62: recipe for target 'tests/CMakeFiles/simple_struct.dir/testprogs/simple_struct.c.o' failed
tests/CMakeFiles/simple_struct.dir/build.make:61: *** [tests/CMakeFiles/simple_struct.dir/testprogs/simple_struct.c.o] Error 1

(I am building using clang-7 at the implied direction of https://github.com/iovisor/bpftrace/blob/master/INSTALL.md#building-bpftrace-1).

I was able to workaround the problem by altering the root CMakeLists.txt like so:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9e5f5c..f416bda 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,9 +96,6 @@ include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
 add_subdirectory(src/arch)
 add_subdirectory(src/ast)
 add_subdirectory(src)
-if (BUILD_TESTING)
-  add_subdirectory(tests)
-endif()
 add_subdirectory(resources)
 add_subdirectory(tools)
 add_subdirectory(man)

@mmarchini
Copy link
Contributor

Interesting, thanks for reporting this @asutherland, I'll take a look.

You can also work around this issue by passing -DBUILD_TESTING=OFF to cmake (instead of changing CMakeLists.txt).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build Issues or PRs related to bpftrace building
Projects
None yet
Development

No branches or pull requests

3 participants