TheComet / ik

Minimal Inverse Kinematics library
MIT License
496 stars 71 forks source link

Cannot compile sample code #7

Closed jillemash closed 4 years ago

jillemash commented 4 years ago

Hi,

I was trying to build devel branch and run the example on my Mac (https://github.com/TheComet/ik#example-usage). CMake works, make -j8 works and make install is error free as well. But I cut'n pasted the example code and just tried to compile it on the command line, but it does not compile. With the c++ command I get that ik is not declared:

$ c++ -std=c++17 -I ../install/include/  main.c
main.c:5:9: error: use of undeclared identifier 'ik'
    if (ik.init() != IK_OK)

And in C:

clang -I ../install/include/  main.c
main.c:5:16: error: called object type '<dependent type>' is not a function or function pointer
    if (ik.init() != IK_OK)

I didn't change the default value of IK_API_NAME, but I also explicitely set it to 'ik', nothing changed.

Here are the only changes I've made to devel:

$ git diff
diff --git a/ik/CMakeLists.txt b/ik/CMakeLists.txt
index 918c007..02765a9 100644
--- a/ik/CMakeLists.txt
+++ b/ik/CMakeLists.txt
@@ -78,7 +78,8 @@ set (IK_COMPILER ${CMAKE_C_COMPILER_ID})
 find_program (UNAME_PROGRAM uname)
 if (UNAME_PROGRAM)
     execute_process (
-        COMMAND ${UNAME_PROGRAM} -ormpi
+        #COMMAND ${UNAME_PROGRAM} -ormpi
+        COMMAND ${UNAME_PROGRAM}  -r -m -p
         OUTPUT_VARIABLE IK_HOST_COMPUTER)
     string (REPLACE "\n" "" IK_HOST_COMPUTER ${IK_HOST_COMPUTER})
 else ()
@@ -452,8 +453,8 @@ install (
     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 install (
     DIRECTORY
-        "include/public/ik"
-        "${CMAKE_CURRENT_BINARY_DIR}/include/public/ik"
+        "include/ik"
+        "${CMAKE_CURRENT_BINARY_DIR}/include/ik"
     DESTINATION
         ${CMAKE_INSTALL_INCLUDEDIR})

Thanks for your help.

TheComet commented 4 years ago

Hey! The devel branch is not guaranteed to compile, and when it does, it's usually broken. Especially as of late because I've been trying (and failing) at implementing cache coherency optimizations.

I recommend you switch to master and let me know if anything is wrong there.

jillemash commented 4 years ago

Hi,

thanks for your answer. The error about undeclared "ik" is gone indeed.

At first I couldn't link with clang

c++ -I ../install/include/ -L../install/lib -lik  main.c
d: library not found for -lik

I've build ik as both static and shared lib. The reason was apparently that the produced library name does not start with lib. I've renamed it as libik.dylib and it found it. Then at runtime I had another error where it didn't find the dyn lib, an rpath issue maybe but I didn't investigate. I've decided to link statically by just adding the abs path of the lib on the command line: c++ -I ../install/include/ main.c /Users/jmhenaff/work/ik/install/lib/ik.a

And now it runs. Just wanted to share how I managed to make it run, I figured it could be useful to add such instructions in the documentation, to set up the code example in the README. Maybe the sample could be pushed with a CMake file in the repo, so that people can directly use it easily.

Thanks!

TheComet commented 4 years ago

Yeah the reason for removing the lib prefix is so that python can find it. I should make it so it only does that if IK_PYTHON=ON.

If you're using CMake for your project you should be able to just add_subdirectory("ik/ik") and then target_link_libraries (myapp PRIVATE ik).

Or alternatively, if you install the library somewhere, it also installs cmake files with it so you should be able to call find_package (ik REQUIRED) and then target_link_libraries (myapp PRIVATE ik).

jillemash commented 4 years ago

Ok great thanks for your help! I won't be trying to use CMake in a near future, so I'll close the issue, I'll re-open it if I encounter an issue with that.

Thanks.