From 8be6b24ae3046010e6b556a21d5e3aa89374826e Mon Sep 17 00:00:00 2001 From: mkoop Date: Fri, 17 Feb 2023 16:14:21 +0100 Subject: [PATCH] extension: windows: Fixed linking extension example to uhd.lib Symtom to observed Example of how to use a (new) feature/behavior --- host/docs/extension.dox | 11 ----- .../examples/extension_example/CMakeLists.txt | 45 ++++++++++++++++--- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/host/docs/extension.dox b/host/docs/extension.dox index 71f466fc1..e930ad056 100644 --- a/host/docs/extension.dox +++ b/host/docs/extension.dox @@ -14,17 +14,6 @@ example in the examples directory. It can be built by Depending on your UHD installation prefix root privileges may be required for `make install`. -Known issue: -When using the Python API with an extension installed, `import uhd` may throw an error: - -`Error: EnvironmentError: OSError: dlopen failed to load "/path/to/libextension.so"` - -If this occurs, please provide the LD_PRELOAD variable with the path to the uhdlib: - -export LD_PRELOAD=[UHD_PREFIX]/lib/libuhd.so - -Afterwards start Python again in the same commandline. - \section extension_capabilities Capabilities of the Extension Framework The Extension Framework attaches to multi_usrp and will work for all RFNoC-capable devices. diff --git a/host/examples/extension_example/CMakeLists.txt b/host/examples/extension_example/CMakeLists.txt index 5cb094254..0f840f7e3 100644 --- a/host/examples/extension_example/CMakeLists.txt +++ b/host/examples/extension_example/CMakeLists.txt @@ -42,7 +42,7 @@ include(UHDBoost) # need these include and link directories for the build include_directories( - ${CMAKE_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS} ${UHD_INCLUDE_DIRS} ) @@ -55,16 +55,49 @@ list(APPEND extexample_sources ) add_subdirectory(include) -message(STATUS "UHD Module Path (to which the extension will be linked):") -message(STATUS ${UHD_MODULE_PATH}) +message(STATUS ${PROJECT_NAME} " linking against library found at:") +message(STATUS " " ${UHD_LIB_PATH}) ### Make the executable ####################################################### add_library(extexample SHARED ${extexample_sources}) +##set(CMAKE_BUILD_TYPE "Release") +message(STATUS "******************************************************************************") +message(STATUS "* NOTE: When building your own app, you probably need all kinds of different ") +message(STATUS "* compiler flags. This is just an example, so it's unlikely these settings ") +message(STATUS "* exactly match what you require. Make sure to double-check compiler and ") +message(STATUS "* linker flags to make sure your specific requirements are included. ") +message(STATUS "******************************************************************************") + +# Shared library case: All we need to do is link against the library, and +# anything else we need (in this case, some Boost libraries): +if(NOT UHD_USE_STATIC_LIBS) + message(STATUS "Linking against shared UHD library.") + target_link_libraries(extexample ${UHD_LIBRARIES} ${Boost_LIBRARIES}) +# Shared library case: All we need to do is link against the library, and +# anything else we need (in this case, some Boost libraries): +else(NOT UHD_USE_STATIC_LIBS) + message(STATUS "Linking against static UHD library.") + target_link_libraries(extexample + # We could use ${UHD_LIBRARIES}, but linking requires some extra flags, + # so we use this convenience variable provided to us + ${UHD_STATIC_LIB_LINK_FLAG} + # Also, when linking statically, we need to pull in all the deps for + # UHD as well, because the dependencies don't get resolved automatically + ${UHD_STATIC_LIB_DEPS} + ) +endif(NOT UHD_USE_STATIC_LIBS) + ### Once it's built... ######################################################## # Here, you have commands to install your program. -set(extension_target ${CMAKE_INSTALL_PREFIX}/lib/libextexample.so) +if(UNIX) + # On Linux OS install into folder and symlink to UHD_MODULE_PATH + set(extension_target ${CMAKE_INSTALL_PREFIX}/lib/libextexample.so) + install(TARGETS extexample DESTINATION lib) + install(CODE "execute_process(COMMAND bash -c \"mkdir -p ${UHD_MODULE_PATH} && ln -s -f ${extension_target} -t ${UHD_MODULE_PATH}\")") +else(UNIX) + # on other OS (Windows) install into UHD_MODULE_PATH + install(TARGETS extexample DESTINATION ${UHD_MODULE_PATH}) +endif(UNIX) -install(TARGETS extexample DESTINATION lib) -install(CODE "execute_process(COMMAND bash -c \"mkdir -p ${UHD_MODULE_PATH} && ln -s -f ${extension_target} -t ${UHD_MODULE_PATH}\")")