Home › Forum › SOFA › Building SOFA › Writing a scene in cpp fails
Tagged: 64_bits, GCC, Linux_ubuntu, scene in cpp, SOFA_1712
- This topic has 24 replies, 4 voices, and was last updated 6 years, 5 months ago by Hugo.
-
AuthorPosts
-
7 June 2018 at 12:13 #11161agnivBlocked
I would like to write a scene in cpp.
For this, I was trying to compile the demo application provided in sofa/applications/tutorials/chainHybrid/
I created a ‘build’ directory under tutorials/chainHybrid/ and run
cmake ..
from the directory.I get the following output:
CMake Warning at CMakeLists.txt:6 (find_package): By not providing "FindSofaGui.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SofaGui", but CMake did not find one. Could not find a package configuration file provided by "SofaGui" with any of the following names: SofaGuiConfig.cmake sofagui-config.cmake Add the installation prefix of "SofaGui" to CMAKE_PREFIX_PATH or set "SofaGui_DIR" to a directory containing one of the above files. If "SofaGui" provides a separate development package or SDK, be sure it has been installed. CMake Warning at CMakeLists.txt:7 (find_package): By not providing "FindSceneCreator.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SceneCreator", but CMake did not find one. Could not find a package configuration file provided by "SceneCreator" with any of the following names: SceneCreatorConfig.cmake scenecreator-config.cmake Add the installation prefix of "SceneCreator" to CMAKE_PREFIX_PATH or set "SceneCreator_DIR" to a directory containing one of the above files. If "SceneCreator" provides a separate development package or SDK, be sure it has been installed. -- Configuring done -- Generating done -- Build files have been written to: /sofa/applications/tutorials/chainHybrid/build
However, I have already built and installed SOFA, including the GUI and SceneCreator components. Not sure why it is complaining! Nevertheless, when I compile using
make
, I get the following output:/sofa/applications/tutorials/chainHybrid/chainHybrid.cpp:23:10: fatal error: SceneCreator/SceneCreator.h: No such file or directory #include <SceneCreator/SceneCreator.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. CMakeFiles/chainHybrid.dir/build.make:62: recipe for target 'CMakeFiles/chainHybrid.dir/chainHybrid.cpp.o' failed make[2]: *** [CMakeFiles/chainHybrid.dir/chainHybrid.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/chainHybrid.dir/all' failed make[1]: *** [CMakeFiles/chainHybrid.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
Could you please help me find out what is going wrong.
(I am using Ubuntu 17.10)
7 June 2018 at 14:33 #11162HugoKeymasterHi @agniv,
Welcome to the SOFA forum!
The tutorial chainHybrid is an old C++ tutorial that has been deprecated in the v17.12. It was previously a project directly in SOFA that could be compiled by activating the flag BUILD_TUTORIALS.I would rather advise to have a look at the tutorial-scenes in examples/Tutorials/
Best
Hugo
7 June 2018 at 14:40 #11163agnivBlockedI have the following folders in examples/Tutorials/ folder:
Basic Collision ForceFields Mappings OldTutorials sandbox Solvers StepByStep Topologies
But none of them seem to contain any cpp files.
I do understand how to create a simple scene using XML and to solve it. But how do I do the same using cpp?
Best,
Agniv.7 June 2018 at 14:46 #11164HugoKeymasterHi @agniv,
Indeed these folders contains scenes that can be run with runSofa. These are not cpp scenerio.
To write a scene in cpp have you looked in the doc: How to write a scene in CPP ?Best
Hugo
7 June 2018 at 15:02 #11165agnivBlockedHi,
I have tried to build the demo scene. Here’s what I do:
I have the following directory structure:
sofa_scene
|
+—>build/
|
+—>CMakeLists.txt
|
+—>Main.cppThe Main.cpp is an exact copy from the tutorial.
The CMakeLists.txt contains:
cmake_minimum_required(VERSION 3.1) project(sofa_scene) find_package(SofaFramework REQUIRED) find_package(SofaComponentCommon) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaFramework SofaComponentCommon)
When I run
cmake ..
from the build directory, I get:CMake Error at CMakeLists.txt:4 (find_package): By not providing "FindSofaFramework.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SofaFramework", but CMake did not find one. Could not find a package configuration file provided by "SofaFramework" with any of the following names: SofaFrameworkConfig.cmake sofaframework-config.cmake Add the installation prefix of "SofaFramework" to CMAKE_PREFIX_PATH or set "SofaFramework_DIR" to a directory containing one of the above files. If "SofaFramework" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred! See also "sofa_scene/build/CMakeFiles/CMakeOutput.log".
Again, not sure what is happening here. Please help.
Best Regards,
Agniv.7 June 2018 at 15:50 #11166HugoKeymasterHi @agniv,
You are here creating a project that is based on SOFA (more especially the SofaFramework package). Therefore cmake is asking for the path to the library. At the configure time, you need to specify the path to SofaFramework. Best
Hugo
7 June 2018 at 16:09 #11167agnivBlockedHow do I do that? I tried setting SofaFramework_DIR to the build path, but that did not work.
7 June 2018 at 16:21 #11168HugoKeymasterHi @agniv,
This is indeed the variable SofaFramework_DIR that you have to fill with the path to the build directory of SOFA.
Hugo
7 June 2018 at 16:42 #11169agnivBlockedSo I change the Cmake file to:
cmake_minimum_required(VERSION 3.1) project(Sofa) set(SofaFramework_DIR "/path/to/sofa/build/") find_package(SofaFramework REQUIRED) find_package(SofaComponentCommon) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaFramework SofaComponentCommon)
This still does not work!
7 June 2018 at 17:22 #11170HugoKeymastercan you tell us more about your error?
7 June 2018 at 17:24 #11171agnivBlockedI changed the cmake file to:
cmake_minimum_required(VERSION 3.1) project(Sofa) set(SofaFramework_DIR "/path/to/sofa/build/cmake/") find_package(SofaFramework REQUIRED) find_package(SofaComponentCommon) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaFramework SofaComponentCommon)
Looks like that worked! But now I get a different error:
CMake Error at /home/agniv/Code/sofa/build/cmake/SofaFrameworkConfig.cmake:36 (find_package): By not providing "FindTinyXML.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "TinyXML", but CMake did not find one. Could not find a package configuration file provided by "TinyXML" with any of the following names: TinyXMLConfig.cmake tinyxml-config.cmake Add the installation prefix of "TinyXML" to CMAKE_PREFIX_PATH or set "TinyXML_DIR" to a directory containing one of the above files. If "TinyXML" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): CMakeLists.txt:6 (find_package) -- Configuring incomplete, errors occurred! See also "/home/agniv/Code/sofa_scene/build/CMakeFiles/CMakeOutput.log". Makefile:176: recipe for target 'cmake_check_build_system' failed make: *** [cmake_check_build_system] Error 1
But I had installed SOFA using TinyXML.
7 June 2018 at 17:29 #11172HugoKeymasterHum ..
first of all you can simply write for the target_link_libraries:
target_link_libraries(${PROJECT_NAME} SofaComponentCommon)
does this help in anyway?7 June 2018 at 17:33 #11173agnivBlockedIf I link it with just SofaComponentCommon, I get a different output:
CMake Warning at CMakeLists.txt:7 (find_package): By not providing "FindSofaComponentCommon.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SofaComponentCommon", but CMake did not find one. Could not find a package configuration file provided by "SofaComponentCommon" with any of the following names: SofaComponentCommonConfig.cmake sofacomponentcommon-config.cmake Add the installation prefix of "SofaComponentCommon" to CMAKE_PREFIX_PATH or set "SofaComponentCommon_DIR" to a directory containing one of the above files. If "SofaComponentCommon" provides a separate development package or SDK, be sure it has been installed. -- Configuring done -- Generating done -- Build files have been written to: /path/to/sofa_scene/build
I tried doing
make
with this output. It does not compile, I get the error message:[ 50%] Building CXX object CMakeFiles/Sofa.dir/Main.cpp.o /path/to/sofa_scene/Main.cpp:5:10: fatal error: sofa/helper/ArgumentParser.h: No such file or directory #include <sofa/helper/ArgumentParser.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. CMakeFiles/Sofa.dir/build.make:62: recipe for target 'CMakeFiles/Sofa.dir/Main.cpp.o' failed make[2]: *** [CMakeFiles/Sofa.dir/Main.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Sofa.dir/all' failed make[1]: *** [CMakeFiles/Sofa.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
7 June 2018 at 18:43 #11174HugoKeymasterWhat simulation do you want to do exactly with this Main.cpp ?
Could you please paste all #include of your Main?
8 June 2018 at 09:50 #11175agnivBlockedThe same code as given in: the demo.
I do not want Main.cpp to do much, as of now. I just want it to compile with full functionality, so that I can play around with it, and eventually do a FEM simulation of sorts.
9 June 2018 at 09:33 #11180jnbrunetModeratorHi,
Instead of manually specify ‘SofaFramework_DIR’ and other Sofa CMAKE dependencies, you can simply set the CMAKE variable ‘CMAKE_PREFIX_PATH’ to the sofa’s CMAKE installation path.
1. In your sofa’s build directory, make sure your ran ‘make’ and ‘make install’ commands. Note the sofa’s install directory path (it seems that in your case, it should be /home/agniv/Code/sofa/build/install)
2. In your scene project, add the ‘CMAKE_PREFIX_PATH’ variable and set its value to /home/agniv/Code/sofa/build/install/lib/cmake
3. Rerun ‘cmake’ and ‘make’ in your scene project build directory
11 June 2018 at 10:15 #11183agnivBlockedHi,
My CMakeLists.txt, in the SOFA scene project, now reads:
cmake_minimum_required(VERSION 3.1) project(Sofa) set(CMAKE_PREFIX_PATH "/path/to/sofa/build/install/lib/cmake") find_package(SofaComponentCommon) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaComponentCommon)
I ran
make
andsudo make install
in the SOFA build directory already.The folder in /path/to/sofa/build/install/lib/cmake contains the following sub-directories:
-
CImg
CImgPlugin
CSparse
GTest
Newmat
QGLViewer
SceneCreator
SofaAdvanced
SofaBase
SofaCommon
SofaFramework
SofaGeneral
SofaGTestMain
SofaGui
SofaMisc
SofaMiscCollision
SofaPython
SofaSimulation
SofaTest
TinyXMLHowever, when I run
cmake ..
in the build directory of the SOFA scene demo project, I see the following output:-- The C compiler identification is GNU 7.2.0 -- The CXX compiler identification is GNU 7.2.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning at CMakeLists.txt:9 (find_package): By not providing "FindSofaComponentCommon.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "SofaComponentCommon", but CMake did not find one. Could not find a package configuration file provided by "SofaComponentCommon" with any of the following names: SofaComponentCommonConfig.cmake sofacomponentcommon-config.cmake Add the installation prefix of "SofaComponentCommon" to CMAKE_PREFIX_PATH or set "SofaComponentCommon_DIR" to a directory containing one of the above files. If "SofaComponentCommon" provides a separate development package or SDK, be sure it has been installed. -- Configuring done -- Generating done -- Build files have been written to: /path/to/sofa_scene/build
If I ignore the warning and run the
make
command, I get the following:[ 50%] Building CXX object CMakeFiles/Sofa.dir/Main.cpp.o /path/to/sofa_scene/Main.cpp:5:10: fatal error: sofa/helper/ArgumentParser.h: No such file or directory #include <sofa/helper/ArgumentParser.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. CMakeFiles/Sofa.dir/build.make:62: recipe for target 'CMakeFiles/Sofa.dir/Main.cpp.o' failed make[2]: *** [CMakeFiles/Sofa.dir/Main.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Sofa.dir/all' failed make[1]: *** [CMakeFiles/Sofa.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
12 June 2018 at 12:26 #11188egarcmBlockedHi @agniv,
I have the same problem writing my cpp scene. Could you check the CMakeCache file? I found a couple of issues, some lines in the file are empty, and I’m not sure if this is the problem.
In line 1491: TinyXML_LIB_DEPENDS:STATIC =
But, similarly:
In line 1692: csparse_LIB_DEPENDS:STATIC=
Line 1720: miniFlowVR_LIB_DEPENDS:STATIC=
Line 1729: newmat_LIB_DEPENDS:STATIC=I suppose that, perhaps, there is a problem in the CMakeLists files and cmake does not build this libraries.
12 June 2018 at 14:07 #11190agnivBlockedHi @egarcm,
Do you mean
sofa_scene/build/CMakeCache.txt
?I do not have those strings in that file! In a fresh build, I do not have nearly as many lines as that.
12 June 2018 at 14:10 #11191egarcmBlockedNop! Directly in the Sofa folder:
“/path/to/sofa/build/CMakeCache.txt”
12 June 2018 at 14:58 #11192agnivBlocked@egarcm Ah! Yes, those fields are empty, indeed!
Did you figure out a workaround? Is that actually the root cause?
(What OS are you using, btw? I have a suspicion, the interaction between TinyXML and Ubuntu 17 might be going wrong in my case!)
12 June 2018 at 15:10 #11193egarcmBlockedI’m working in Ubuntu 14.04 and, so far, I havn’t a solution. Even, I don’t know if it is the cause.
12 June 2018 at 17:35 #11198HugoKeymasterHi Agniv,
The code you got inspired from is a template : it means you need to implement it your own way. Especially the function addMyComponent in which you need to add a SOFA component that does exist or that you implemented.
First of all, I would for instance remove unnecessary includes e.g.:
#include <SofaComponentCommon/initComponentCommon.h> #include <SofaComponentBase/initComponentBase.h> #include <SofaComponentGeneral/initComponentGeneral.h> #include <SofaComponentAdvanced/initComponentAdvanced.h> #include <SofaComponentMisc/initComponentMisc.h>
and remove this from the code:
sofa::component::initComponentBase(); sofa::component::initComponentCommon(); sofa::component::initComponentGeneral(); sofa::component::initComponentAdvanced(); sofa::component::initComponentMisc();
Since the code uses ArgumentParser, Node, possibly PluginManager etc. you need to declare the associated package dependencies in your CMakeLists.txt:
cmake_minimum_required(VERSION 3.1) project(Sofa) set(CMAKE_PREFIX_PATH "/path/to/sofa/build/install/lib/cmake") find_package(SofaFramework) find_package(SofaSimulation) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaComponentCommon SofaHelper SofaDefaultType SofaCore SofaSimulationCommon SofaSimulationTree SofaSimulationGraph)
and you need then to run:
1. cmake-gui ../path_to_the_source and set the path to SOFA build dir for all *_DIR required
2. make
3. run your executable generated in your buildNote that you also can get inspired from the Main.cpp of runSofa (sofa/applications/projects).
Cheers,Hugo
13 June 2018 at 16:10 #11202agnivBlockedHi Hugo,
Stripping down the code to the basics, and using the CMakeLists.txt you suggested results in the following compilation error:
/usr/bin/ld: cannot find -lSofaComponentCommon collect2: error: ld returned 1 exit status CMakeFiles/Sofa.dir/build.make:130: recipe for target 'Sofa' failed make[2]: *** [Sofa] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Sofa.dir/all' failed make[1]: *** [CMakeFiles/Sofa.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
I played around a bit and changed the CMakeLists.txt to:
cmake_minimum_required(VERSION 3.1) project(Sofa) set(SofaFramework_DIR "path/to/sofa/build/install/lib/cmake") set(SofaCommon_DIR "path/to/sofa/build/install/lib/cmake") set(CMAKE_PREFIX_PATH "path/to/Code/sofa/build/install/lib/cmake") link_directories("path/to/sofa/build/install/lib") #find_package(SofaFramework REQUIRED) find_package(SofaCommon) find_package(SofaFramework) find_package(SofaSimulation) find_package(SofaGui) find_package(SofaBase REQUIRED SofaComponentBase) add_executable(${PROJECT_NAME} Main.cpp) target_link_libraries(${PROJECT_NAME} SofaComponentCommon SofaComponentBase SofaHelper SofaDefaultType SofaCore SofaSimulationTree SofaSimulationGraph SofaGuiMain)
This allows the code to compile. But It results in the following runtime error while running the generated executable:
./Sofa: error while loading shared libraries: libSofaSimulationCommon.so.18.06.dev: cannot open shared object file: No such file or directory
I tweaked this a bit, but keep running into similar runtime errors, including errors from libSofaComponentBase etc.
FYI… the new cpp code looks like this:
#include <sstream> using std::ostringstream ; #include <fstream> #include <sofa/helper/ArgumentParser.h> #include <SofaSimulationCommon/common.h> #include <sofa/simulation/Node.h> #include <sofa/helper/system/PluginManager.h> #include <sofa/simulation/config.h> #include <SofaSimulationTree/init.h> #include <SofaSimulationTree/TreeSimulation.h> #include <sofa/helper/BackTrace.h> int main(int argc, char** argv) { sofa::helper::BackTrace::autodump(); sofa::simulation::setSimulation(new sofa::simulation::tree::TreeSimulation()); std::ostringstream no_error_message; std::cout<<"All OK!"<<std::endl; return 0; }
never managed to get till printing “All OK!”.
What can be done next?
Cheers,
Agniv.27 June 2018 at 17:51 #11243HugoKeymasterIf I am correct, the include
#include <SofaSimulationCommon/common.h>
is obsolete and not needed. -
AuthorPosts
- You must be logged in to reply to this topic.