Skip to content
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

Fix rosconsole build issue when built on Windows #13

Merged
merged 4 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ install(DIRECTORY include/
if(CATKIN_ENABLE_TESTING)
catkin_add_gtest(${PROJECT_NAME}-utest test/utest.cpp)
if(TARGET ${PROJECT_NAME}-utest)
target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME} ${LOG4CXX_LIBRARIES})
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
Expand All @@ -122,6 +122,6 @@ if(CATKIN_ENABLE_TESTING)

catkin_add_gtest(${PROJECT_NAME}-thread_test test/thread_test.cpp)
if(TARGET ${PROJECT_NAME}-thread_test)
target_link_libraries(${PROJECT_NAME}-thread_test ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}-thread_test ${PROJECT_NAME} ${LOG4CXX_LIBRARIES})
endif()
endif()
17 changes: 15 additions & 2 deletions include/ros/console_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
#ifndef ROSCONSOLE_CONSOLE_BACKEND_H
#define ROSCONSOLE_CONSOLE_BACKEND_H

#include <ros/macros.h>

// Import/export for windows dll's and visibility for gcc shared libraries.
#ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
#ifdef rosconsole_backend_interface_EXPORTS // we are building a shared lib/dll
#define ROSCONSOLE_BACKEND_DECL ROS_HELPER_EXPORT
#else // we are using shared lib/dll
#define ROSCONSOLE_BACKEND_DECL ROS_HELPER_IMPORT
#endif
#else // ros is being built around static libraries
#define ROSCONSOLE_BACKEND_DECL
#endif

namespace ros
{
namespace console
Expand All @@ -55,11 +68,11 @@ namespace backend

void notifyLoggerLevelsChanged();

extern void (*function_notifyLoggerLevelsChanged)();
ROSCONSOLE_BACKEND_DECL extern void (*function_notifyLoggerLevelsChanged)();

void print(void* logger_handle, ::ros::console::Level level, const char* str, const char* file, const char* function, int line);

extern void (*function_print)(void*, ::ros::console::Level, const char*, const char*, const char*, int);
ROSCONSOLE_BACKEND_DECL extern void (*function_print)(void*, ::ros::console::Level, const char*, const char*, const char*, int);

} // namespace backend
} // namespace console
Expand Down
15 changes: 6 additions & 9 deletions src/rosconsole/impl/rosconsole_log4cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ROSConsoleStdioAppender : public log4cxx::AppenderSkeleton
}
#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(tmpstr, event->getMessage()); // has to handle LogString with wchar types.
std::string msg = tmpstr // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
std::string msg = tmpstr; // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
#else
std::string msg = event->getMessage();
#endif
Expand Down Expand Up @@ -171,9 +171,6 @@ void initialize()
if ( config_file_cstr != NULL ) {
free(config_file_cstr);
}
if ( format_string != NULL ) {
free(format_string);
}
// getenv implementations don't need free'ing.
#endif
}
Expand Down Expand Up @@ -208,7 +205,7 @@ std::string getName(void* handle)
const log4cxx::spi::LoggingEvent* event = (const log4cxx::spi::LoggingEvent*)handle;
#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(tmpstr, event->getLoggerName()); // has to handle LogString with wchar types.
return tmpstr // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
return tmpstr; // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
#else
return event->getLoggerName();
#endif
Expand All @@ -223,11 +220,11 @@ bool get_loggers(std::map<std::string, levels::Level>& loggers)
log4cxx::LoggerList::iterator end = current_loggers.end();
for (; it != end; ++it)
{
std::string name;
#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(name, (*it)->getName()); // has to handle LogString with wchar types.
LOG4CXX_ENCODE_CHAR(tmpstr, (*it)->getName()); // has to handle LogString with wchar types.
std::string name = tmpstr;
#else
name = (*it)->getName();
std::string name = (*it)->getName();
#endif

const log4cxx::LevelPtr& log4cxx_level = (*it)->getEffectiveLevel();
Expand Down Expand Up @@ -334,7 +331,7 @@ class Log4cxxAppender : public log4cxx::AppenderSkeleton

#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(tmpstr, event->getMessage()); // has to handle LogString with wchar types.
std::string msg = tmpstr // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
std::string msg = tmpstr; // tmpstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
#else
std::string msg = event->getMessage();
#endif
Expand Down
12 changes: 12 additions & 0 deletions test/thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

#include "log4cxx/appenderskeleton.h"
#include "log4cxx/spi/loggingevent.h"
#ifdef _MSC_VER
// Have to be able to encode wchar LogStrings on windows.
#include "log4cxx/helpers/transcoder.h"
#endif

#include <vector>

Expand All @@ -57,8 +61,16 @@ class TestAppender : public log4cxx::AppenderSkeleton
{
Info info;
info.level_ = event->getLevel();
#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(msgstr, event->getMessage()); // has to handle LogString with wchar types.
info.message_ = msgstr; // msgstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro

LOG4CXX_ENCODE_CHAR(loggerstr, event->getLoggerName()); // has to handle LogString with wchar types.
info.logger_name_ = loggerstr; // loggerstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
#else
info.message_ = event->getMessage();
info.logger_name_ = event->getLoggerName();
#endif

info_.push_back( info );
}
Expand Down
12 changes: 12 additions & 0 deletions test/utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#include "log4cxx/appenderskeleton.h"
#include "log4cxx/spi/loggingevent.h"
#ifdef _MSC_VER
// Have to be able to encode wchar LogStrings on windows.
#include "log4cxx/helpers/transcoder.h"
#endif

#include <vector>
#include <stdexcept>
Expand Down Expand Up @@ -58,8 +62,16 @@ class TestAppender : public log4cxx::AppenderSkeleton
{
Info info;
info.level_ = event->getLevel();
#ifdef _MSC_VER
LOG4CXX_ENCODE_CHAR(msgstr, event->getMessage()); // has to handle LogString with wchar types.
info.message_ = msgstr; // msgstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro

LOG4CXX_ENCODE_CHAR(loggerstr, event->getLoggerName()); // has to handle LogString with wchar types.
info.logger_name_ = loggerstr; // loggerstr gets instantiated inside the LOG4CXX_ENCODE_CHAR macro
#else
info.message_ = event->getMessage();
info.logger_name_ = event->getLoggerName();
#endif

info_.push_back( info );
}
Expand Down