-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
spdlog and nlohmann/json are incompatible ? #2764
Comments
How is it related with the with nlohmanjson? |
I had initially noticed that by not including the nlohmann library, the messages were printing correctly. However, now, doing new tests, it would appear that there is no connection with that library. At the moment I don't understand... |
I'm sorry, I made a mistake. The topic title is wrong because there is no link to the nlohmann/json library. In fact, by not including the library, the bug still occurs. |
Perhaps the test.cpp get compiled before main.cpp and before the SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE is defined. |
Seems that order is correct pi@raspberrypi:~/test_logger $ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/test_logger
pi@raspberrypi:~/test_logger $ make
[ 33%] Building CXX object CMakeFiles/app.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/app.dir/test.cpp.o
[100%] Linking CXX executable app
[100%] Built target app
pi@raspberrypi:~/test_logger $ ./app
TRACE: 1
DEBUG: 1
INFO: 1
WARN: 1
ERROR: 1
CRITICAL: 1
[2023-06-16 15:47:33.249] [test.cpp:16] [info] Test
[2023-06-16 15:47:33.249] [test.cpp:17] [warning] Test
[2023-06-16 15:47:33.249] [test.cpp:18] [error] Test
[2023-06-16 15:47:33.249] [test.cpp:19] [critical] Test
pi@raspberrypi:~/test_logger $ Wait..If I move pi@raspberrypi:~/test_logger $ make
Scanning dependencies of target app
[ 33%] Building CXX object CMakeFiles/app.dir/main.cpp.o
In file included from /home/pi/test_logger/main.cpp:9:
/home/pi/test_logger/test.h:4: warning: "SPDLOG_ACTIVE_LEVEL" redefined
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
In file included from /usr/local/include/spdlog/spdlog.h:12,
from /home/pi/test_logger/main.cpp:5:
/usr/local/include/spdlog/common.h:228: note: this is the location of the previous definition
# define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
[ 66%] Building CXX object CMakeFiles/app.dir/test.cpp.o
[100%] Linking CXX executable app
[100%] Built target app
pi@raspberrypi:~/test_logger $ ./app
TRACE: 1
DEBUG: 1
INFO: 1
WARN: 1
ERROR: 1
CRITICAL: 1
[2023-06-16 15:53:26.156] [test.cpp:14] [trace] Test
[2023-06-16 15:53:26.156] [test.cpp:15] [debug] Test
[2023-06-16 15:53:26.156] [test.cpp:16] [info] Test
[2023-06-16 15:53:26.156] [test.cpp:17] [warning] Test
[2023-06-16 15:53:26.156] [test.cpp:18] [error] Test
[2023-06-16 15:53:26.156] [test.cpp:19] [critical] Test |
Try defining if as a compiler flag, or in each compilation unit |
Thanks for your hint. I've removed cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 14)
set(PROJECT_NAME app)
project(${PROJECT_NAME})
set(PROJECT_SOURCE_DIR .)
file(GLOB SOURCE_FILES
${PROJECT_SOURCE_DIR}/*.cpp
${PROJECT_SOURCE_DIR}/*.h
)
find_package(spdlog REQUIRED)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} spdlog::spdlog) Now the output is correct. I think that should be mentioned in the wiki |
Great. The wiki is open for all to edit. Feel free to add it there. |
I'm going crazy with this...
main.cpp
config/test.h
config/test.cpp
Console output
Expected console output
This is a bug or I'm doing something wrong ?
The text was updated successfully, but these errors were encountered: