Difficulty building ROS with Fuzzylite library

asked 2021-09-29 19:25:24 -0500

ModernNoob gravatar image

updated 2021-09-30 19:50:30 -0500

I downloaded a fuzzy logic library from https://github.com/fuzzylite/fuzzylite. I placed the library within the workspace like this: src ├─workspace ├── CMakeLists.txt ├── scripts ├── fuzzylite-6.0 ├── missions │ ├── fuzzy │ └──fuzzy.h

There was a previous question with a similar issue, however, the developer simply asked the OP to look at the example CMakeLists.txt he provided. Code:

project(FuzzyLiteDemo CXX)

#Some default policies and variables
if (APPLE)
    cmake_policy(SET CMP0042 NEW)
endif()
if (MSVC)
    cmake_policy(SET CMP0054 NEW)
endif()

if(NOT CMAKE_VERBOSE_MAKEFILE)
    set(CMAKE_VERBOSE_MAKEFILE false)
endif()

if( NOT CMAKE_BUILD_TYPE )
    set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo
MinSizeRel." FORCE )
endif()

option(FL_BACKTRACE "Provide backtrace information in case of errors" ON)
option(FL_STATIC "Statically link to fuzzylite libraries" ON)

set(BacktraceLibrary)

if (MSVC AND FL_BACKTRACE)
    set(BacktraceLibrary dbghelp)
endif()

if (CMAKE_BUILD_TYPE MATCHES Debug)
    set(FL_DEBUG ON)
else()
    set(FL_DEBUG OFF)
endif()


set(FL_SYSTEM_LIBRARY FALSE) #Finds the library installed in the system
set(FL_LIBRARY_DIR)

if (NOT FL_SYSTEM_LIBRARY)
    #it is possible to find the FuzzyLiteLibrary locally as follows,
    #assuming the submodule of fuzzylite is added to the ${PROJECT_SOURCE_DIR}:
    set(FL_HOME ${PROJECT_SOURCE_DIR}/../../fuzzylite/)
    set(FL_INCLUDE_DIR ${FL_HOME})
    if (FL_DEBUG)
        set(FL_LIBRARY_DIR ${FL_HOME}/debug/bin)
    else()
        set(FL_LIBRARY_DIR ${FL_HOME}/release/bin)
    endif()
    message("Finding FuzzyLiteLibrary locally at ${FL_LIBRARY_DIR}")

    include_directories(${FL_INCLUDE_DIR})
endif()

set(FL_POSTFIX)
if (FL_STATIC)
    set(FL_POSTFIX "-static")
endif()
if (FL_DEBUG)
    set(FL_POSTFIX "${FL_POSTFIX}-debug")
endif()

set(FL_LIBRARY_NAME  fuzzylite${FL_POSTFIX})
find_library (FuzzyLiteLibrary ${FL_LIBRARY_NAME} HINTS ${FL_LIBRARY_DIR})

if (MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
#C++11 not available before Visual Studio 2015
    if (NOT FL_CPP98)
        set(FL_CPP98 ON)
    endif()
endif()


#if building using C++98
if(FL_CPP98)
    add_definitions(-DFL_CPP98)
    if(NOT MSVC)
        #Set C++98 by default in Clang and others
        add_definitions(-std=c++98)
    endif()
else()
    if(NOT MSVC)
        #Set C++11 by default in Clang and others
        add_definitions(-std=c++11)
    endif()
endif(FL_CPP98)

#we add the definition of the building path to remove it when using macro FL_LOG
add_definitions(-DFL_BUILD_PATH="${CMAKE_SOURCE_DIR}") #used to determine

#we add the sources
set(sources src/main.cpp)


if(MSVC)
#Set compilation flags in Windows
    set(CMAKE_CXX_FLAGS "/W4 /EHsc")
    #Wx: Treat warnings as errors. W4: All warnings
    #http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
    #EHsc: call destructors on __try __catch, and to ignore C4530: C++ exception handler used. Note, unwind semantics are not enabled
endif()



#we create the binary
add_executable(binary ${sources})
if (NOT FL_STATIC)

    target_compile_definitions(binary PRIVATE FL_IMPORT_LIBRARY)
endif()
#linking the fuzzylite library
target_link_libraries (binary ${FuzzyLiteLibrary} ${BacktraceLibrary})
#setting the name of the product
set_target_properties(binary PROPERTIES OUTPUT_NAME FuzzyLiteDemo)
#specially for windows
set_target_properties(binary PROPERTIES OUTPUT_NAME FuzzyLiteDemo IMPORT_PREFIX tmp-) #To prevent LNK1149 in Windows
#in case of building on debug mode
set_target_properties(binary PROPERTIES DEBUG_POSTFIX d)

I pasted this piece of code into my CMakeLists.txt file after changing FL_HOME /scripts/fuzzylite-6.0/fuzzylite and attempted to build it but this continues to give me an error. I am not sure what is wrong and my CMake skills are not very good.

The Error that I received after editing the CMakeLists ... (more)

edit retag flag offensive close merge delete

Comments

Could you clarify how this is ROS-related? You appear to have a workspace directory, which could be a Catkin workspace, but it has a scripts subdirectory, which is not something we recognise here.

Catkin also can't build regular CMake packages (well, not without a package.xml anyway).

Or are you trying to build a ROS package and use fuzzylite as a system dependency?

Finally:

There was a previous question

which? Where?

with a similar issue

what issue? You haven't described what your issue is. You've only stated "this continues to give me an error".

however, the developer

which developer? The author of fuzzylite?

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 02:41:30 -0500 )edit

@gvdhoom Sorry for the vague post. This is indeed a caktin workspace for ROS 1. I will edit the content of the post to answer all your questions. I've also edited the tree of my program by changing the name to what ROS will normally look like. Previously, I was able to link custom C++ headers and it source codes, but this is an external library, so I am not quite sure what to do/put in the CMakeLists.txt. The only thing that provided any real hint is the CMakeList.txt provided by the developer of Fuzzylite (https://github.com/fuzzylite/fuzzylite), which I attempted to just copy and past then change the path of FL_HOME to the path of the library, but that obviously didn't work in my case.

ModernNoob gravatar image ModernNoob  ( 2021-09-30 19:47:41 -0500 )edit

In addition to @gvdhoom advice please also check more details on the fuzzylite package. In the issues section there is information how to find fuzzylite with CMake linking locally:

set(FL_SYSTEM_LIBRARY FALSE) #Finds the library installed in the system
 set(FL_LIBRARY_DIR)

 if (NOT FL_SYSTEM_LIBRARY)
     #it is possible to find the FuzzyLiteLibrary locally as follows,
     #assuming the submodule of fuzzylite is added to the ${PROJECT_SOURCE_DIR}:
     set(FL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/fuzzylite/fuzzylite)
     set(FL_LIBRARY_DIR ${PROJECT_SOURCE_DIR}/fuzzylite/fuzzylite/release/bin)
     message("Finding FuzzyLiteLibrary locally at ${FL_LIBRARY_DIR}")

     include_directories(${FL_INCLUDE_DIR})
 endif()

 find_library (FuzzyLiteLibrary fuzzylite HINTS ${FL_LIBRARY_DIR})
osilva gravatar image osilva  ( 2021-09-30 20:15:35 -0500 )edit

@osilva I had tried that many time after changing the Path, but I always receive the same result. No progress. I had tried to contact the developer by creating an issue https://github.com/fuzzylite/help/issues/7 and it appears that perhaps my post is being ignored probably due to it simplicity. I am not sure what else to do.

ModernNoob gravatar image ModernNoob  ( 2021-10-02 19:14:29 -0500 )edit