Adding pre-built .o file(s) to CMakeLists.txt

4,276 views
Skip to first unread message

Gennadiy Rishkin

unread,
Oct 4, 2013, 9:38:50 AM10/4/13
to dea...@googlegroups.com
Hi

Does anyone know the correct way to add an object file to CMakELists.txt for coorect compilation. So, using step-4 as an example, if I had say, make_grid() precompiled into make_grid.o, how would I then include it for compilation using cmake.

thanks

Gennadiy

Matthias Maier

unread,
Oct 4, 2013, 9:57:16 AM10/4/13
to dea...@googlegroups.com
You just list the object file(s) together with the source files.


If you use the "autopilot" style CMakeLists.txt from the examples, just
list them together with the sources:

SET(TARGET_SRC
step-4.cc
make_grid.o
)


If you have a custom CMakeLists.txt [1],

ADD_EXECUTABLE(step-4
step-4.cc
make_grid.o
)

Also have a look at the object target explained in [2].

Best,
Matthias


[1] http://www.dealii.org/developer/index.html
[2] http://www.dealii.org/developer/users/cmakelists.html#cmakesimple.libs

Gennadiy Rishkin

unread,
Oct 8, 2013, 10:30:18 AM10/8/13
to dea...@googlegroups.com
Thanks Matthias. I'm using the "autopilot" style CMakeLists.txt from the examples. When I do:

SET(TARGET_SRC
  step-4.cc
  make_grid.o
)

I get the error:

CMakeFiles/main.dir/main.cc.o: In function `Step4<3>::run()':
main.cc:(.text._ZN7Step4ILi3EE3runEv[Step4<3>::run()]+0x80): undefined reference to `Step4<3>::make_grid()'

Thanks,

Gennadiy



--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Matthias Maier

unread,
Oct 8, 2013, 10:51:56 AM10/8/13
to dea...@googlegroups.com

Am 08. Oct 2013, 16:30 schrieb Gennadiy Rishkin <gennadiy...@gmail.com>:

> Thanks Matthias. I'm using the "autopilot" style CMakeLists.txt from
> the examples. When I do:
>
> SET(TARGET_SRC
>   step-4.cc
>   make_grid.o
> )
>
> I get the error:
>
> CMakeFiles/main.dir/main.cc.o: In function `Step4<3>::run()':
> main.cc:(.text._ZN7Step4ILi3EE3runEv[Step4<3>::run()]+0x80):
> undefined reference to `Step4<3>::make_grid()'

Does make_grid have the same function signature in both files and do you
instantiate make_grid in make_grid.o?

And, why do you use such a setup in the first place?

Best,
Matthias

Gennadiy Rishkin

unread,
Oct 11, 2013, 9:51:53 AM10/11/13
to dea...@googlegroups.com
hi Matthias,

Yes, make_grid has the same function signature in both files.
I have the step4 class definition and the necessary headers in "step4.h", the other classes including 'main' in step4.cc.
make_grid.cc includes step4.h as a header and then I compile make_grid.cc to make_grid.o using "g++ -O3 -I/path_to_required_headers -c make_grid.cc".
Then I add make_grid.o to SET(TARGET_SRC step4.cc make_grid.o)
But it still doesn't work.

I'm trying this to understand how to link a prebuilt object file (for which I do not have the source file) from an external library to deal.II.

Thanks.


Gennadiy




Matthias Maier

unread,
Oct 11, 2013, 10:17:59 AM10/11/13
to dea...@googlegroups.com
For a templated function/class in C++ it is not sufficient to just declare
and define them, you have to instantiate them as well if they reside in
a different compilation unit. Have you done that?

An example:

foo.h:

/* Function declaration: */
template<int i> void foo();


foo.cc

/* Function definition: */
template<int i> void foo()
{
return;
}

/* Explicit instantiation: */
template void foo<1>();
Reply all
Reply to author
Forward
0 new messages