Import OpenSim in Linux

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Import OpenSim in Linux

Post by Ana de Sousa » Mon Nov 16, 2020 12:22 pm

Hello, I have some trouble building OpenSim CPP files in Linux.

I have already successfully installed OpenSim in Ubuntu 20.04. I know it works because all tests passed, and I can import OpenSim in python files and use functions (when I create the environment variable: export OPENSIM_HOME=~/opensim/install/lib ).

However, I am having some trouble importing the library in CPP files.

In a CmakeLists file, I set the environment variables, append the CMAKE_MODULE_PATH for finding OpenSim, try to find OpenSim, include directories, and add the subdirectory src:

Code: Select all

project(test)
cmake_minimum_required(VERSION 3.2.0)

# Settings.
# ---------
set( ENV{OPENSIM_HOME} /home/ana/opensim/install/include )
set( ENV{OPENSIM_INCLUDE_DIR} /home/ana/opensim/install/include )
set( ENV{OPENSIM_INSTALL_DIR}  /home/ana/opensim/install/include )
message(STATUS "OPENSIM_HOME: $ENV{OPENSIM_HOME}")
message(STATUS "OPENSIM_INSTALL_DIR: $ENV{OPENSIM_INSTALL_DIR}")
message(STATUS "OPENSIM_INCLUDE_DIR: $ENV{OPENSIM_INCLUDE_DIR}")
message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")

# Find and hook up to OpenSim.
# ----------------------------
find_package(OpenSim REQUIRED)
include_directories(${OPENSIMSIMBODY_INCLUDE_DIRS})

# Add source code.
# ----------------------------
add_subdirectory(src)

When running "cmake", it only works when I set OPENSIM_HOME either as /home/ana/opensim/install/include or /home/ana/opensim/opensim-core. Reading the FindOpenSim file, I understood that is because it finds OpenSim/OpenSim.h .

However, when I try to actually build the project, it gives back: fatal error: OpenSim.h: No such file or directory.

In FindOpenSim. cmake also says that OPENSIM_INSTALL_DIR has the highest priority in finding the path, but it only works when I change OPENSIM_HOME. Moreover, if I build it after it says it found OpenSim, it gives the message saying it didn't. So, I got the feeling that I am doing something really wrong here.

I appreciate any help.

Tags:

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Import OpenSim in Linux

Post by Ayman Habib » Mon Nov 16, 2020 1:21 pm

Hello,

Please compare what you have in your CMakeLists.txt file with the distributed CPP examples, the latest version is found on github here
https://github.com/opensim-org/opensim- ... xampleMain

and let us know what you find out since we can't reproduce your environment. The environment variable OPENSIM_HOME has been deprecated, so please avoid relying on it in your CMake files.

Best regards,
-Ayman

User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Re: Import OpenSim in Linux

Post by Ana de Sousa » Mon Nov 16, 2020 1:51 pm

Hello Ayman,

Thank you for your response, I copied all files from the repository, and tested with the following CMakeLists.txt:

Code: Select all

project(OpenSimTugOfWar)

cmake_minimum_required(VERSION 3.2)

# Settings.
# ---------
# set(TARGET exampleMain CACHE TYPE STRING)
set(OPENSIM_INSTALL_DIR $ENV{OPENSIM_HOME}
        CACHE PATH "Top-level directory of OpenSim install")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")

# OpenSim uses C++11 language features.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find and hook up to OpenSim.
# ----------------------------
find_package(OpenSim REQUIRED PATHS "${OPENSIM_INSTALL_DIR}")

# Configure this project.
# -----------------------
file(GLOB SOURCE_FILES *.h *.cpp)

add_executable(${TARGET} ${SOURCE_FILES})

target_link_libraries(${TARGET} ${OpenSim_LIBRARIES})

# This block copies the additional files into the running directory
# For example vtp, obj files. Add to the end for more extentions
file(GLOB DATA_FILES *.vtp *.obj)
foreach(dataFile ${DATA_FILES})
    add_custom_command(
        TARGET ${TARGET}
        COMMAND ${CMAKE_COMMAND}
        ARGS -E copy
        ${dataFile}
        ${CMAKE_BINARY_DIR})
endforeach(dataFile)

In this file, which you say it is the latest version, it relies on OPENSIM_HOME, doesn't it?
If so, how can I fix it?

When I run 'cmake .' in this environment, I get:

Code: Select all

CMake Warning (dev) at CMakeLists.txt:7 (set):
  implicitly converting 'TYPE' to 'STRING' type.
If I comment this line (edit: which is a warning, so it does not matter as much), I get:

Code: Select all

Could not find a package configuration file provided by "OpenSim" with any
  of the following names:

    OpenSimConfig.cmake
    opensim-config.cmake

User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Re: Import OpenSim in Linux

Post by Ana de Sousa » Mon Nov 16, 2020 2:16 pm

[FIXED]

I added the path to OpenSimConfig.cmake at the beginning:

Code: Select all

set(OpenSim_DIR "/home/ana/opensim/install/lib/cmake/OpenSim")
Thank you for the help indicating the latest file!

POST REPLY