Crow icon indicating copy to clipboard operation
Crow copied to clipboard

ISO C++11 requires whitespace after the macro name

Open stephanecharette opened this issue 2 years ago • 18 comments

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.

stephanecharette avatar Apr 03 '22 03:04 stephanecharette

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?

The-EDev avatar Apr 04 '22 15:04 The-EDev

I wonder why it can't be found, it is set by getting the interface compile definitions of the Crow::Crow target...

luca-schlecker avatar Apr 04 '22 16:04 luca-schlecker

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?

The-EDev avatar Apr 12 '22 01:04 The-EDev

Like I wrote in the original comment, if I don't use Crow::Crow then the error goes away.

stephanecharette avatar Apr 12 '22 06:04 stephanecharette

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.

stephanecharette avatar Apr 12 '22 06:04 stephanecharette

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})

stephanecharette avatar Apr 12 '22 06:04 stephanecharette

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 avatar May 27 '22 10:05 MichaelSB

@MichaelSB I believe using add_subdirectory removes the need to use target_link_libraries

The-EDev avatar May 28 '22 06:05 The-EDev

@MichaelSB I believe using add_subdirectory removes the need to use target_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.

luca-schlecker avatar Jun 27 '22 12:06 luca-schlecker

my bad :)

The-EDev avatar Jun 27 '22 12:06 The-EDev

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?

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.

luca-schlecker avatar Jun 27 '22 12:06 luca-schlecker

And I also believe that using interface shouldn't be necessary for the executable.

luca-schlecker avatar Jun 27 '22 12:06 luca-schlecker

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.

luca-schlecker avatar Jun 27 '22 12:06 luca-schlecker

@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.

luca-schlecker avatar Jun 27 '22 12:06 luca-schlecker

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 avatar Jun 27 '22 12:06 The-EDev

@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 avatar Jun 27 '22 12:06 luca-schlecker

@luca-schlecker actually I can just send my test project here, to compile (at least for me):

  • mkdir build
  • cd build
  • cmake ..
  • make

testingiso.zip

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.

The-EDev avatar Jun 27 '22 12:06 The-EDev

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.

akjt avatar Aug 02 '22 13:08 akjt

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:

  1. add target_compile_definitions(Crow INTERFACE "") before line 65 in CMakeLists.txt, or
  2. improve the logic in CrowConfig.cmake to check for the existence of INTERFACE_COMPILE_DEFINITIONS previous to calling get_target_property(_CROW_ICD Crow::Crow INTERFACE_COMPILE_DEFINITIONS)

Enjoy

hlmodi avatar Oct 27 '22 18:10 hlmodi

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?

yvzhex avatar Aug 03 '23 06:08 yvzhex

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")

yvzhex avatar Aug 04 '23 09:08 yvzhex

should be solved by https://github.com/CrowCpp/Crow/pull/720

gittiver avatar Mar 10 '24 20:03 gittiver