Crow
Crow copied to clipboard
ISO C++11 requires whitespace after the macro name
Attempting to build example from https://crowcpp.org/getting_started/your_first_application/ I'm on Ubuntu 20.04.4, so using g++ 9.4.0-1ubuntu1 and cmake 3.16.3.
Installed Crow .deb file. In my own CMakeLists.txt, relevant lines are:
ADD_DEFINITIONS ("-Wall -Wextra -Werror -Wno-unused-parameter")
FIND_PACKAGE (Crow REQUIRED)
FIND_PACKAGE (Threads REQUIRED)
...
TARGET_LINK_LIBRARIES (example Threads::Threads Crow::Crow ...more...)
When I attempt to build, I get the following:
> make
[ 50%] Building CXX object CMakeFiles/example.dir/main.cpp.o
<command-line>: error: ISO C++11 requires whitespace after the macro name [-Werror]
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/example.dir/build.make:63: CMakeFiles/example.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
What is not obvious is what macro could be causing this error, and where this is being called from.
If I remove -Werror
then the warning is still there, but build step completes. But I'd rather keep -Werror
enabled and fix the warning.
If I remove Crow::Crow from the TARGET_LINK_LIBRARIES line, then the error goes away and the build step completes as well.
I can confirm the issue does occur, this is my CMakeLists.txt
:
project (example)
ADD_DEFINITIONS ("-Wall -Wextra -Werror -Wno-unused-parameter")
add_executable(example main.cpp)
set(Crow_DIR lib/cmake/Crow)
FIND_PACKAGE (Crow REQUIRED)
target_link_libraries(example PUBLIC Crow::Crow)
The problem is that CrowConfig.cmake
is adding -D_CROW_ICD-NOTFOUND
, which is invalid.. This could mean that Crow cannot find INTERFACE_COMPILE_DEFINITIONS
and thus creating this definition. @luca-schlecker what do you think?
I wonder why it can't be found, it is set by getting the interface compile definitions of the Crow::Crow
target...
I managed to get my code to compile without error by using target_link_libraries(example INTERFACE Crow::Crow)
, I also had to use target_include_directories(example PUBLIC "include")
to include the Crow headers.
@stephanecharette can you check if this solution works for you?
Like I wrote in the original comment, if I don't use Crow::Crow
then the error goes away.
have you tried setting cmake_minimum_required(VERSION 3.22)
No I have not, since I am using CMake 3.16.3 that comes with Ubuntu 20.04.
I see what you mean. And no, this doesn't work for me, while that error goes away, I cannot get it to link with OpenSSL and the other libraries I need for HTTPS and the various other things this application requires.
I've never used the keyword INTERFACE
in TARGET_LINK_LIBRARIES
. Maybe I'm using it wrong? This is what my CMakeLists looks like right now:
...
ADD_DEFINITIONS ("-DCROW_ENABLE_SSL")
FIND_PACKAGE (Crow REQUIRED)
FIND_PACKAGE (OpenSSL REQUIRED)
...
ADD_EXECUTABLE (example ${SOURCE})
TARGET_INCLUDE_DIRECTORIES (example PUBLIC "include")
TARGET_LINK_LIBRARIES (example INTERFACE Crow::Crow Threads::Threads ${OPENSSL_LIBRARIES} ${DARKHELP} ${DARKNET} ${OpenCV_LIBS})
The only way I found to get this to compile and link without error is to change it to this:
...
ADD_DEFINITIONS ("-DCROW_ENABLE_SSL")
FIND_PACKAGE (Crow REQUIRED)
FIND_PACKAGE (OpenSSL REQUIRED)
...
ADD_EXECUTABLE (example ${SOURCE})
TARGET_LINK_LIBRARIES (example Threads::Threads ${OPENSSL_LIBRARIES} ${DARKHELP} ${DARKNET} ${OpenCV_LIBS})
I usually add crow as git submodule and add it with add_subdirectory(...) to my project. Like
cmake_minimum_required(VERSION 3.10)
cmake_policy(VERSION 3.10)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(example VERSION 1.0.0)
add_subdirectory(external/crow)
add_executable(example main.cc)
target_link_libraries(example PUBLIC Crow::Crow)
and building always worked for me, also when I linked additional libraries to the target. Probably the PUBLIC in target_link_libraries? Or because of add_subdirectory?
@MichaelSB I believe using add_subdirectory
removes the need to use target_link_libraries
@MichaelSB I believe using
add_subdirectory
removes the need to usetarget_link_libraries
It doesn't.
add_subdirectory
only adds it to the project and makes the target available, it must still be linked, that's also how the headers are made available.
my bad :)
I can confirm the issue does occur, this is my
CMakeLists.txt
:project (example) ADD_DEFINITIONS ("-Wall -Wextra -Werror -Wno-unused-parameter") add_executable(example main.cpp) set(Crow_DIR lib/cmake/Crow) FIND_PACKAGE (Crow REQUIRED) target_link_libraries(example PUBLIC Crow::Crow)
The problem is that
CrowConfig.cmake
is adding-D_CROW_ICD-NOTFOUND
, which is invalid.. This could mean that Crow cannot findINTERFACE_COMPILE_DEFINITIONS
and thus creating this definition. @luca-schlecker what do you think?
Feels to me like somehow these two lines are not working as intended:
get_target_property(_CROW_ICD Crow::Crow INTERFACE_COMPILE_DEFINITIONS)
set_target_properties(Crow::Crow PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${_CROW_ICD}"
INTERFACE_LINK_LIBRARIES "${_CROW_ILL}"
)
Maybe a Problem with the .deb
file?
I installed Crow manually on my Windows system using CMake's install target and consuming it worked out fine.
And I also believe that using interface
shouldn't be necessary for the executable.
I usually add crow as git submodule and add it with add_subdirectory(...) to my project. Like
cmake_minimum_required(VERSION 3.10) cmake_policy(VERSION 3.10) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) project(example VERSION 1.0.0) add_subdirectory(external/crow) add_executable(example main.cc) target_link_libraries(example PUBLIC Crow::Crow)
and building always worked for me, also when I linked additional libraries to the target. Probably the PUBLIC in target_link_libraries? Or because of add_subdirectory?
Using Crow like this is a supported scenario and should just work.
@stephanecharette Have you tried a different route then the .deb
file? Maybe try the subdirectory approach or manually install Crow without the .deb
by using the install target.
I didn't exactly use the .deb file, but all the packages Crow provides (except conan and VCPKG) contain the lib
directory that has CrowConfig.cmake
and CrowTargets.cmake
, and I was getting the same error.
@The-EDev could you please hook me up with instructions sent via email so I can properly replicate this error. Then I may be able to find out more about this issue.
@luca-schlecker actually I can just send my test project here, to compile (at least for me):
-
mkdir build
-
cd build
-
cmake ..
-
make
Note I'm pretty sure the headers and cmake files are outdated, I think I haven't updated them since I first looked into this issue.
This issue seems to still be persisting? Why do we need to add INTERFACE before it can link? And correct having Crow as a subdirectory seems to work, but on many occasion you prefer to have it properly installed in your local system.
Following CrowConfig.cmake:
include("${CMAKE_CURRENT_LIST_DIR}/CrowTargets.cmake")
check_required_components("Crow")
get_target_property(_CROW_ILL Crow::Crow INTERFACE_LINK_LIBRARIES)
get_target_property(_CROW_ICD Crow::Crow INTERFACE_COMPILE_DEFINITIONS)
In order for get_target_property
not to yield <var>-NOTFOUND
will require that INTERFACE_LINK_LIBRARIES
and INTERFACE_COMPILE_DEFINITIONS
are defined in CrowTargets.cmake:
set_target_properties(Crow::Crow PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "Boost::boost;Boost::system;Boost::date_time;Threads::Threads"
)
So I manually forced it to:
set_target_properties(Crow::Crow PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "Boost::boost;Boost::system;Boost::date_time;Threads::Threads"
INTERFACE_COMPILE_DEFINITIONS ""
)
So 2 paths here:
- add
target_compile_definitions(Crow INTERFACE "")
before line 65 in CMakeLists.txt, or - improve the logic in CrowConfig.cmake to check for the existence of
INTERFACE_COMPILE_DEFINITIONS
previous to callingget_target_property(_CROW_ICD Crow::Crow INTERFACE_COMPILE_DEFINITIONS)
Enjoy
hi, i use release v1.0.5 and meet similar issue. can you give me some advice to fix it and when will be a new release?
i add master in my project, in the occassion that not open the ssl and compression feature, the same issue happen.
so i change the cmake as follows, and it is ok.
CMakeLists.txt
# Possible values: ssl, compression
#option(CROW_FEATURES "Enable features extending Crow's abilities" "")
set(CROW_FEATURES "ssl;compression")
should be solved by https://github.com/CrowCpp/Crow/pull/720