Adding extra sources to a project

Hello list,

After
orocreate-pkg Helloworld
I try to extend the generated example by adding something simple to the generated support.cpp file.
But the build fails.
My support.cpp is:

#ifdef __cplusplus
extern "C" {
#endif

int testit(void) {return 1;}

#ifdef __cplusplus
}
#endif

Then this function is called in Helloworld-component.cpp as follows.

int testit(void);
bool Helloworld::configureHook(){
std::cout << "Helloworld configured !" <<std::endl;
return testit();
}

But the build fails as follows:

[ 4%] Building CXX object src/CMakeFiles/Helloworld.dir/Helloworld-component.cpp.o
Linking CXX shared library libHelloworld-gnulinux.so
CMakeFiles/Helloworld.dir/Helloworld-component.cpp.o: In function `Helloworld::configureHook()':
Helloworld-component.cpp:(.text+0xbb): undefined reference to `testit()'
collect2: ld returned 1 exit status
make[3]: *** [src/libHelloworld-gnulinux.so] Error 1

If I remove the call to testit, the build is completed correctly and the support binary is created in
build/src/CMakeFiles/support.dir/support.cpp.o

If I then add the call to testit again it still fails, even is an object file is now available.

There probably is some Cmake error?
What am I doing wrong? Why can the object file generated from support.cpp not be found?

Thanks in advance,
Sietse

>

Ruben Smits's picture

Adding extra sources to a project

Hi Sietse,

On Tue, Jun 10, 2014 at 2:31 PM, Sietse Achterop <s [dot] achterop [..] ...> wrote:
> Hello list,
>
> After
> orocreate-pkg Helloworld
> I try to extend the generated example by adding something simple to the generated support.cpp file.
> But the build fails.
> My support.cpp is:
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> int testit(void) {return 1;}
>
> #ifdef __cplusplus
> }
> #endif
>
> Then this function is called in Helloworld-component.cpp as follows.
>
> int testit(void);
> bool Helloworld::configureHook(){
> std::cout << "Helloworld configured !" <<std::endl;
> return testit();
> }
>
> But the build fails as follows:
>
> [ 4%] Building CXX object src/CMakeFiles/Helloworld.dir/Helloworld-component.cpp.o
> Linking CXX shared library libHelloworld-gnulinux.so
> CMakeFiles/Helloworld.dir/Helloworld-component.cpp.o: In function `Helloworld::configureHook()':
> Helloworld-component.cpp:(.text+0xbb): undefined reference to `testit()'
> collect2: ld returned 1 exit status
> make[3]: *** [src/libHelloworld-gnulinux.so] Error 1
>
> If I remove the call to testit, the build is completed correctly and the support binary is created in
> build/src/CMakeFiles/support.dir/support.cpp.o
>
> If I then add the call to testit again it still fails, even is an object file is now available.
>
> There probably is some Cmake error?
> What am I doing wrong? Why can the object file generated from support.cpp not be found?

Are you building the support.cpp into the component library (list it
as second source file in the orocos_component cmake macro in the
CMakeLists.txt)? Or as a separate library? If the latter, are you
linking with the separate library ( something along the lines of
target_link_libraries(Helloworld support) )

Ruben

> Thanks in advance,
> Sietse
>
>
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users

Adding extra sources to a project

On 10-06-14 16:21, Ruben Smits wrote:

Hello Ruben,
> Are you building the support.cpp into the component library (list it
> as second source file in the orocos_component cmake macro in the
> CMakeLists.txt)?

When doing "orocreate-pkg" a number of file are created, including src/CMakeLists.txt.
I added support.cpp to orocos_component, and commented out the last line.
It now contains (with all comments removed):

orocos_component(Helloworld Helloworld-component.hpp Helloworld-component.cpp support.cpp)
orocos_install_headers(Helloworld-component.hpp)
orocos_plugin(Helloworld-plugin Helloworld-plugin.cpp)
orocos_service(Helloworld-service Helloworld-service.cpp)
#orocos_library(support support.cpp)

The file support.cpp was empty, but I added a trivial function and assumed it could be
called in Helloworld-component.cpp.
But with the Cmakelists above i get the same error.

Or as a separate library? If the latter, are you
> linking with the separate library ( something along the lines of
> target_link_libraries(Helloworld support) )

Adding
target_link_libraries(Helloworld support)
to the oroginal makelists-file didn't help.

How should src/CMakeLists.txt look when i want to use support.cpp in my component?
Am I having a Cmake problem or an Orocos problem?

Thanks in advance,
Sietse

PS for completeness i attached the output of the make.