Multiple source files and a linking problem...

24 views
Skip to first unread message

heikki

unread,
Feb 4, 2018, 10:52:13 AM2/4/18
to deal.II User Group
Hello, 

I have project where I would like to use multiple source and header files that are in /source and /include subfolders. The CMakelists.txt is in the root. Otherwise the program can be compiled without errors but I am getting some linking errors. 

In function `main':
undefined reference to `poisson::PProblem<2>::declare_parameters()'
undefined reference to `poisson::PProblem<2>::run()'


My CMakelists.txt follows the one presented in this discussion but I have fixed the paths to the files:


Since it is a templated object, I have provided the following instantiations in the source files.

foo.h: 
/* Declaration: */
template<int dim>
class PProblem {};

foo.cpp: 
namespace pdd {
/* Definition ... */
/* Instantiation: */
template class PProblem<2> p_test_problem;
}

Do you have any suggestions or comments, how to solve the linking problem? 

-Heikki

heikki

unread,
Feb 4, 2018, 11:54:09 AM2/4/18
to deal.II User Group
I put the definitions to the headers. That at least works and it is probably a sufficient solution for me.

-H

Wolfgang Bangerth

unread,
Feb 4, 2018, 5:38:19 PM2/4/18
to dea...@googlegroups.com, heikki
On 02/04/2018 08:52 AM, heikki wrote:
>
> foo.cpp:
> |
> namespace pdd {
> /* Definition ... */
> /* Instantiation: */
> template class PProblem<2> p_test_problem;
> }
> |

I suspect that the last line here is supposed to be an *explicit
instantiation* of the main class, but I think it's really just a variable
declaration. It should really just be
template class PProblem<2>;

Take a look also here:
https://stackoverflow.com/questions/2351148/explicit-instantiation-when-is-it-used

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Reply all
Reply to author
Forward
0 new messages