Dear deal.ii developers and user community,
Happy New Year! 🎊
I'm trying to split source code into different directories following to this documentation
Unfortunately, I keep getting the following error in linking step between libmylib.a and main:
"/projappl/project_xxxx/PDE/main.cc:115:undefined reference to `MyNamespace_mpi::pde_solver<3>::pde_solver(unsigned int)
/projappl/project_xxxx/PDE/main.cc:116: undefined reference to `MyNamespace_mpi::pde_solver<3>::run()'
collect2: error: ld returned 1 exit status
'"
I didn't get this error when all members and class declarations are located in one source *cc file.
My source layout is
PDE
|--main.cc
|--CMakeLists.txt
|--mylib
|--CMakeLists.txt
|--header1.h
|--header2.h
|--source.cc
, where header1.h declares MyNamespace_mpi and pde_solver<>, with source.cc implementing all members in pde_solver<>.
And header2.h defines dirichlet boundary condition functions in namespace MyNamespace_mpi.
Following documentation, I wrote PDE/CMakeLists.txt as
"
cmake_minimum_required(VERSION 3.13.4)
find_package(deal.II 9.3.3 REQUIRED
HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
deal_ii_initialize_cached_variables()
project(cmaketest)
include_directories(mylib)
link_directories(mylib)
add_subdirectory(mylib)
add_executable(mycode main.cc)
deal_ii_setup_target(mycode)
target_link_libraries(mycode mylib)
"
and PDE/mylib/CMakeLists.txt as
"
add_library(mylib
source.cc
header1.h
header2.h
)
deal_ii_setup_target(mylib)
"
I need source directory layout because I have many new functions that must be added into pde_solver<>.
It seems it is a linking problem. I'm not sure if it is related to the pre-built deal.ii library.
I hope developers and deal.ii's users can give me suggestions to solve this issue.
Best,
Tim