I have a trouble with `googletest` (`libgtest.a`) ...
# linux
y
I have a trouble with
googletest
(
libgtest.a
) while compiling osquery using qcreator on
4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) x86_64 GNU/Linux
. It compiles with
make
though. Have anyone experienced such problem? I tried to install
googletest
and
libgtest-dev
packages and ran
make deps
already.
Copy code
17:13:40: Running steps for project OSQUERY...
17:13:40: Starting: "/usr/local/bin/cmake" --build . --target all
[  1%] Linking CXX static library libgtest.a
Error running link command: No such file or directory
third-party/googletest/googlemock/gtest/CMakeFiles/gtest.dir/build.make:83: recipe for target 'third-party/googletest/googlemock/gtest/libgtest.a' failed
make[2]: *** [third-party/googletest/googlemock/gtest/libgtest.a] Error 2
make[1]: *** [third-party/googletest/googlemock/gtest/CMakeFiles/gtest.dir/all] Error 2
CMakeFiles/Makefile2:369: recipe for target 'third-party/googletest/googlemock/gtest/CMakeFiles/gtest.dir/all' failed
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
17:13:40: The process "/usr/local/bin/cmake" exited with code 2.
Error while building/deploying project OSQUERY (kit: Desktop)
When executing step "Make"
17:13:40: Elapsed time: 00:00.
It took me quite a while to figure everything out and I'm glad to share the solution now. The main idea is to pass all the toolchain to the IDE. One of the slack members made a post about preparing your IDE (https://alessandrogar.io/post/osquery-development-with-qtcreator-and-clion/), but it didn't work for me from the first try. I was getting errors from linker unable to find
libc++
, though I had the required flags set in qtcreator for the selected kit and compilers. So I ended up editing CMakeLists a bit to pass this flags, I changed
Copy code
set(CXX_STDLIB "-stdlib=libc++")
to
Copy code
set(CXX_STDLIB "-stdlib=libc++ -L/usr/local/osquery/legacy/lib -L/usr/local/osquery/lib -B/usr/local/osquery/legacy/lib -rtlib=compiler-rt -fuse-ld=lld")
It works just fine, but i'd like to know the way to compile osquery without messing with CMakeLists just by editing IDE parameters, environment variables, etc.
👍 1
o
Great post, I'll try tomorrow to do the same thing for Visual Studio Code, is there a difference?
s
@ycpr what was the issue you were having? One thing that I noticed is that when configuring the environment variables for the kit, the double quotes around LDFLAGS value have to be removed.
👍 1
y
Double quotes seem to be the problem for me as well. I tried to remove them later but the LDFLAGS variable didn't change (maybe I've exported it by hand before).
s
I'm not sure I follow, does it work for you now? Without changing the CMakeLists.txt? One thing to notice is that if you've already configured the project once before removing the double quotes, you need to either do Build->Clear CMake Configuration or delete the build folder
otherwise it will still pick up the wrong value
y
Yes, now it works fine without changing CMakeLists.txt after cleaning CMake configuration in IDE. The only problem were quotes in LDFLAGS environment variable, thanks for the suggestion
🎉 1