Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the example code #11

Open
LordGlamdring opened this issue Oct 13, 2020 · 3 comments
Open

Running the example code #11

LordGlamdring opened this issue Oct 13, 2020 · 3 comments

Comments

@LordGlamdring
Copy link

Hi!

I would like to try to use your software in my school project. For this project in need to make a robot arm move to a specific coordinate. After ready the wiki i wanted to try out the example code form the README file. I ran into some issue's

  1. So i started my virtual machine with an ubuntu 18.04 image.
  2. I ran the required commands
mkdir build && cd build
cmake ../
make -j8
sudo make install
  1. Then i made a new file in another directory and executed the example code from the README with the following command
    sudo g++ -o mytest test.cpp

It did not comple an gave the following errors:

test.cpp: In function ‘int main()’:
test.cpp:10:66: error: invalid conversion from ‘int’ to ‘ik_node_t*’ [-fpermissive]
     struct ik_node_t* child1 = solver->node->create_child(1, root);
                                                                  ^
test.cpp:10:66: error: invalid conversion from ‘ik_node_t*’ to ‘uint32_t {aka unsigned int}’ [-fpermissive]
test.cpp:11:68: error: invalid conversion from ‘int’ to ‘ik_node_t*’ [-fpermissive]
     struct ik_node_t* child2 = solver->node->create_child(2, child1);
                                                                    ^
test.cpp:11:68: error: invalid conversion from ‘ik_node_t*’ to ‘uint32_t {aka unsigned int}’ [-fpermissive]
test.cpp:12:68: error: invalid conversion from ‘int’ to ‘ik_node_t*’ [-fpermissive]
     struct ik_node_t* child3 = solver->node->create_child(3, child2);
                                                                    ^
test.cpp:12:68: error: invalid conversion from ‘ik_node_t*’ to ‘uint32_t {aka unsigned int}’ [-fpermissive]
test.cpp:31:15: error: ‘const struct ik_solver_interface_t’ has no member named ‘rebuild_data’; did you mean ‘rebuild’?
     ik.solver.rebuild_data(solver);
               ^~~~~~~~~~~~
               rebuild

I tried fixing it, but no succes.

  1. Then i tried the example code form Tutorial 2.0
    This gave these errors:
test.cpp: In function ‘int main()’:
test.cpp:4:5: error: ‘ik_init’ was not declared in this scope
     ik_init();
     ^~~~~~~
test.cpp:5:5: error: ‘ik_log_init’ was not declared in this scope
     ik_log_init();
     ^~~~~~~~~~~
test.cpp:8:43: error: ‘ik_uid’ was not declared in this scope
     struct ik_node* base = ik_node_create(ik_uid(0));
                                           ^~~~~~
test.cpp:8:43: note: suggested alternative: ‘ik_node’
     struct ik_node* base = ik_node_create(ik_uid(0));
                                           ^~~~~~
                                           ik_node
test.cpp:8:28: error: ‘ik_node_create’ was not declared in this scope
     struct ik_node* base = ik_node_create(ik_uid(0));
                            ^~~~~~~~~~~~~~
test.cpp:8:28: note: suggested alternative: ‘ik_node_t’
     struct ik_node* base = ik_node_create(ik_uid(0));
                            ^~~~~~~~~~~~~~
                            ik_node_t
test.cpp:9:5: error: ‘IK_INCREF’ was not declared in this scope
     IK_INCREF(base); /* Always have to take ownership of root node */
     ^~~~~~~~~

the list goes on.

I probably made a mistake while setting everything up. mabey i have to put the file i want to compile somewhere specific?
Could you tell me how i can compile one of the examples?

@TheComet
Copy link
Owner

Hey!

The wiki is wrong, the arguments are the other way around. It should be solver->node->create_child(root, 1);

Doing the following seems to work:

#include "ik/ik.h"
int main() {
    /* do your stuff here */
}

And then compiling with:

gcc -W -c -I<path to ik>/ik/include/public -I<path to ik>/build/ik/include/public -o main.o main.c
gcc -o example -lm main.o <path to ik>/build/ik/ik.a

This should produce a binary example. Alternatively you can use cmake. Something like:

cmake_minimum_required (VERSION 2.8)
project ("example" LANGUAGES C)
find_package (IK REQUIRED)
add_executable (example "main.c")
target_link_libraries (example PRIVATE ik)

And then:

mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH=<path to ik>/build/ik ../
make

I recommend using the version that's on master for now, because the API for 2.0 is still fluctuating. Let me know if you have any other problems.

@LordGlamdring
Copy link
Author

Hey!

Thank your for your fast response. I tried both of your suggestions, they appear to break on some undefined references.

First of all i changed the solver->node->create_child(1, root); problem for all calls like your said. Then only one error remained after running this command : gcc -W -c -I<path to ik>/ik/include/public -I<path to ik>/build/ik/include/public -o main.o main.c

error:

main.c: In function ‘main’:
main.c:31:15: error: ‘const struct ik_solver_interface_t’ has no member named ‘rebuild_data’; did you mean ‘rebuild’?
     ik.solver.rebuild_data(solver);
               ^~~~~~~~~~~~
               rebuild

So in changed ik.solver.rebuild_data(solver); to ik.solver.rebuild(solver); Then i ran gcc -W -c -I<path to ik>/ik/include/public -I<path to ik>/build/ik/include/public -o main.o main.c agian and got the main.o file.

Next step was this command gcc -o example -lm main.o <path to ik>/build/ik/ik.a
Unfortunately this is where it broke with this error:

<path to ik>/build/ik/ik.a(quat_static.c.o): In function `ik_quat_static_angle':
quat_static.c:(.text+0x547): undefined reference to `__acos_finite'
quat_static.c:(.text+0x55c): undefined reference to `sincos'
<path to ik>/build/ik/ik.a(quat_static.c.o): In function `ik_quat_static_angle_normalized_vectors':
quat_static.c:(.text+0x610): undefined reference to `__acos_finite'
quat_static.c:(.text+0x625): undefined reference to `sincos'
<path to ik>/build/ik/ik.a(solver_TWO_BONE.c.o): In function `ik_solver_TWO_BONE_solve':
solver_TWO_BONE.c:(.text+0x1f1): undefined reference to `__acos_finite'
solver_TWO_BONE.c:(.text+0x20c): undefined reference to `sincos'
collect2: error: ld returned 1 exit status

After this I tried your cmake suggestion. this runs smoothly until i run the make command, this gave a similar error:

[ 50%] Building C object CMakeFiles/example.dir/main.c.o
[100%] Linking C executable example
/usr/local/lib/ik.a(quat_static.c.o): In function `ik_quat_static_angle':
quat_static.c:(.text+0x547): undefined reference to `__acos_finite'
quat_static.c:(.text+0x55c): undefined reference to `sincos'
/usr/local/lib/ik.a(quat_static.c.o): In function `ik_quat_static_angle_normalized_vectors':
quat_static.c:(.text+0x610): undefined reference to `__acos_finite'
quat_static.c:(.text+0x625): undefined reference to `sincos'
/usr/local/lib/ik.a(solver_TWO_BONE.c.o): In function `ik_solver_TWO_BONE_solve':
solver_TWO_BONE.c:(.text+0x1f1): undefined reference to `__acos_finite'
solver_TWO_BONE.c:(.text+0x20c): undefined reference to `sincos'
collect2: error: ld returned 1 exit status
CMakeFiles/example.dir/build.make:95: recipe for target 'example' failed
make[2]: *** [example] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example.dir/all' failed
make[1]: *** [CMakeFiles/example.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

I take it you did not have these errors? Mabey i am using the wrong gcc or cmake version. I use gcc 7.5.0 and cmake 3.10.2
Do you know how I can solve this?

@TheComet
Copy link
Owner

I would recommend using cmake if you can because it handles all of this for you.

But the error you're getting there has something to do with link order and how libm is being linked. Maybe try moving -lm after ik.a?

gcc -o example main.o <path to ik>/build/ik/ik.a -lm

Also note that you can use make install (and set CMAKE_INSTALL_PREFIX if you need to) to install the ik library, making it easier to link against or find from cmake using find_package(IK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants