Skip to content

Commit

Permalink
Make dynamic loading example work on OSX.
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Aug 11, 2016
1 parent 2e15957 commit 6e02e37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ add_executable(matrix matrix.cpp)
target_link_libraries (matrix yomm11)

if(NOT MSVC)
add_library( dl_shared SHARED dl_shared.cpp )
add_executable(dl_main dl_main.cpp)
add_library( dl_shared SHARED dl_shared.cpp )
if(APPLE)
set_target_properties(dl_main PROPERTIES LINK_FLAGS "-Wl,-export_dynamic")
set_target_properties(dl_shared PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
endif()
target_link_libraries (dl_main yomm11 dl dl_shared)
endif()
8 changes: 7 additions & 1 deletion examples/dl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ int main() {
cout << "encounter(Cow(), Wolf()) -> " << encounter(Cow(), Wolf()) << endl;
cout << "encounter(Wolf(), Cow()) -> " << encounter(Wolf(), Cow()) << endl;

void* handle = dlopen("./libdl_shared.so", RTLD_NOW);
void* handle = dlopen(
#ifdef __APPLE__
"./libdl_shared.dylib"
#else
"./libdl_shared.so"
#endif
, RTLD_NOW);

if (!handle) {
cout << "dlopen() failed: " << dlerror() << "\n";
Expand Down

0 comments on commit 6e02e37

Please sign in to comment.