Skip to content
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ set(${PROJECT_NAME}_HDRS
include/class_loader/multi_library_class_loader.hpp
include/class_loader/register_macro.hpp
)
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS})
if(WIN32)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnsonshih I would expect it to fall back to SHARED if BUILD_SHARED_LIBS is not specified. Did you experience a different behavior on Windows?

Copy link
Author

@johnsonshih johnsonshih Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, class_loader doesn't honor BUILD_SHARED_LIBS and is always built as DLL (it's specified in around line#69, defined CLASS_LOADER_BUILDING_DLL to build as DLL).
I added this line to match the settings so it won't cause problem if BUILD_SHARED_LIBS is Off.

if(WIN32)

  # Causes the visibility macros to use dllexport rather than dllimport

  # which is appropriate when building the dll but not consuming it.

  target_compile_definitions(${PROJECT_NAME} PRIVATE "CLASS_LOADER_BUILDING_DLL")

endif()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @johnsonshih for the additional details.
Would it make sense to set the definition CLASS_LOADER_BUILDING_DLL only if BUILD_SHARED_LIBS is ON rather than ignoring BUILD_SHARED_LIBS and forcing it to always be shared on Windows ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's a good idea. The concern is the static data in class_loader, class_loader is a low level component used by a lot of components. If class_loader is a static library, there will be multiple instances of class_loader static data within one process (that should be only one per process) that might cause unexpected side effect. I will suggest keep it as is.

else()
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS})
endif()

target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${console_bridge_LIBRARIES} ${Poco_LIBRARIES})
if(WIN32)
# Causes the visibility macros to use dllexport rather than dllimport
Expand Down
2 changes: 2 additions & 0 deletions include/class_loader/class_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class ClassLoader
boost::recursive_mutex load_ref_count_mutex_;
int plugin_ref_count_;
boost::recursive_mutex plugin_ref_count_mutex_;

CLASS_LOADER_PUBLIC
static bool has_unmananged_instance_been_created_;
};

Expand Down
4 changes: 3 additions & 1 deletion include/class_loader/meta_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#define CLASS_LOADER__META_OBJECT_HPP_

#include <console_bridge/console.h>
#include "class_loader/visibility_control.hpp"

#include <typeinfo>
#include <string>
#include <vector>
Expand All @@ -54,7 +56,7 @@ typedef std::vector<class_loader::ClassLoader *> ClassLoaderVector;
* @class AbstractMetaObjectBase
* @brief A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templates though.
*/
class AbstractMetaObjectBase
class CLASS_LOADER_PUBLIC AbstractMetaObjectBase
{
public:
/**
Expand Down