diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index be279e1..ba9d55e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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() diff --git a/examples/dl_main.cpp b/examples/dl_main.cpp index b123db8..ab92f02 100644 --- a/examples/dl_main.cpp +++ b/examples/dl_main.cpp @@ -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";