Open teeks99 opened 6 years ago
The error is not related to boost at all, but to rapidjson. How did you install rapidjson? Can you test with the official version 1.1.0 and see if the problem persists?
That happens when I clone the rapidjson repo from https://github.com/Tencent/rapidjson.git then checkout v1.1.0
.
I also tried with ubuntu xenial's default version of boost (1.58), it has a different issue.
(Trivial commands below have output clipped)
# Start with a clean docker image
docker run --rm -it ubuntu:xenial /bin/bash
apt update
# This installs gcc 5, boost 1.58, cmake 3.5.1
apt install build-essential libboost-regex-dev git cmake
mkdir src
cd src
# Get v1.1 of rapidjson
git clone https://github.com/Tencent/rapidjson.git
cd rapidjson
git checkout v1.1.0
cd ..
# Get the example
git clone https://github.com/pabloariasal/modern-cmake-sample.git
cd modern-cmake-sample
mkdir build
cd build
export CMAKE_PREFIX_PATH=/src/rapidjson/
$ cmake ../libjsonutils/
-- The CXX compiler identification is GNU 5.4.0
-- 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
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- regex
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Found RapidJSON: /src/rapidjson/include/rapidjson (Required is at least version "1.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /src/modern-cmake-sample/build/googletest-download
Scanning dependencies of target googletest
[ 11%] Creating directories for 'googletest'
[ 22%] Performing download step (git clone) for 'googletest'
Cloning into 'googletest-src'...
Already on 'master'
Your branch is up-to-date with 'origin/master'.
[ 33%] No patch step for 'googletest'
[ 44%] Performing update step for 'googletest'
Current branch master is up to date.
[ 55%] No configure step for 'googletest'
[ 66%] No build step for 'googletest'
[ 77%] No install step for 'googletest'
[ 88%] No test step for 'googletest'
[100%] Completed 'googletest'
[100%] Built target googletest
-- The C compiler identification is GNU 5.4.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
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /src/modern-cmake-sample/build
$ cmake --build .
Scanning dependencies of target jsonutils
[ 12%] Building CXX object CMakeFiles/jsonutils.dir/src/json_utils.cpp.o
[ 25%] Linking CXX static library libjsonutils.a
[ 25%] Built target jsonutils
Scanning dependencies of target gtest
[ 37%] Building CXX object googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 50%] Linking CXX static library libgtest.a
[ 50%] Built target gtest
Scanning dependencies of target gtest_main
[ 62%] Building CXX object googletest-build/googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 75%] Linking CXX static library libgtest_main.a
[ 75%] Built target gtest_main
Scanning dependencies of target json_utils_test
[ 87%] Building CXX object test/CMakeFiles/json_utils_test.dir/src/main.cpp.o
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp: In member function 'virtual void JsonUtilsTest_loadFromFile_Test::TestBody()':
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:6:10: error: 'doc' does not name a type
auto doc = jsonutils::loadJson("/home/pablo/Documents/test.json");
^
In file included from /src/modern-cmake-sample/build/googletest-src/googletest/include/gtest/gtest.h:58:0,
from /src/modern-cmake-sample/libjsonutils/test/src/main.cpp:1:
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:8:17: error: 'doc' was not declared in this scope
ASSERT_TRUE(doc);
^
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:9:17: error: 'doc' was not declared in this scope
ASSERT_TRUE(doc->HasMember("source"));
^
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:10:10: error: 'source' does not name a type
auto source = (*doc)["source"].GetString();
^
In file included from /src/modern-cmake-sample/build/googletest-src/googletest/include/gtest/gtest.h:360:0,
from /src/modern-cmake-sample/libjsonutils/test/src/main.cpp:1:
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:11:26: error: 'source' was not declared in this scope
ASSERT_STREQ("file", source);
^
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp: In member function 'virtual void JsonUtilsTest_loadFromUrl_Test::TestBody()':
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:16:10: error: 'doc' does not name a type
auto doc = jsonutils::loadJson("https://books.com/novels");
^
In file included from /src/modern-cmake-sample/build/googletest-src/googletest/include/gtest/gtest.h:58:0,
from /src/modern-cmake-sample/libjsonutils/test/src/main.cpp:1:
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:18:17: error: 'doc' was not declared in this scope
ASSERT_TRUE(doc);
^
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:19:17: error: 'doc' was not declared in this scope
ASSERT_TRUE(doc->HasMember("source"));
^
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:20:10: error: 'source' does not name a type
auto source = (*doc)["source"].GetString();
^
In file included from /src/modern-cmake-sample/build/googletest-src/googletest/include/gtest/gtest.h:360:0,
from /src/modern-cmake-sample/libjsonutils/test/src/main.cpp:1:
/src/modern-cmake-sample/libjsonutils/test/src/main.cpp:21:25: error: 'source' was not declared in this scope
ASSERT_STREQ("url", source);
^
test/CMakeFiles/json_utils_test.dir/build.make:62: recipe for target 'test/CMakeFiles/json_utils_test.dir/src/main.cpp.o' failed
make[2]: *** [test/CMakeFiles/json_utils_test.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:126: recipe for target 'test/CMakeFiles/json_utils_test.dir/all' failed
make[1]: *** [test/CMakeFiles/json_utils_test.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
First of all thank you for writing the entire instructions you used. I was in fact able to reproduce your issue. The problem was that the default standard of your g++ version (5.4) is set to c++98. One of the drawbacks of my arch linux setup is that I have g++7.3, which sets the default language standard to --std=c++14
. First world problems. I fixed this by telling CMake that we use auto
, so it should set the language standard accordingly: target_compile_features(json_utils_test PRIVATE cxx_auto_type)
. Please test again.
I also discovered that the docker the image does no have vim installed per default :p first time I have to install vim on a unix system.
That worked fine in my docker example, using the 1.58 boost from the distro.
However, when I manually download/build boost 1.55 from sourceforge and try to use that, I get the original error in this issue. But, if I get the 1.58 from sourceforge and download/build that...it works! I'm guessing that the 1.55 that comes with Arch has some fix backported to it. I'm a bit suprised that arch is still that far back, 1.55 is from late 2013. Maybe just note this somewhere in the blog post?
Does the version of boost you used have some patch applied to optional? I see this error.