Open agk29 opened 8 years ago
There's a good discussion here: http://stackoverflow.com/questions/13694605/how-to-use-c-source-files-in-a-c-project
The accepted answer on this page talks about the things in C that are not compatible with C++. And I know the code has some of these things in it, such as mallocs that are not cast, etc.
The C files can probably still be compiled with a C compiler and then linked to any C++ code - this might be the easiest option
Thanks, @rgbrown.
Yes, now that you remind me, I remember looking at it once to compile it with a C++ compiler and having those issues show up.
Francois and Allanah compiled the code on PAN cluster today to run some simulations. Francois advice was to avoid compiling with C compiler and then use C++ linker, because it complicates the lib paths to be passed to the linker and makes it quite difficult to use it with CMake.
We've started this discussion because without assistance from someone who knows the build system very closely on the target platform, it would have been very difficult to figure it out. CMake is a good tool for cross-platform compatibility, to simplify compilation for any platform.
A bit of a catch-22, situation?
Not exact. I didn't look at all the lines of compilation - I should look more closely. But cmake is instructed to look for mpicxx
. At linking time the C compiler is used and it couldn't resolve libstdc++ needed by libmpicxx. The easiest way was to switch to the C++ compiler to link.
Oh, did I misquote you, @kiwifb. Apologies. Can we have a look at it together when I'm in the lab sometime next week to straighten it out?
After inspection:
ConvertBinToVtu
is C++ code that is indirectly linked to mpi (through libvtkIOMPIParallel.so
).
parBrainSim
is pure C code that is accidentally linked to the C++ mpi library
/usr/bin/cc -Wall -std=c99 -g -Wl,--as-needed CMakeFiles/parBrainSim.dir/src/run_parbrain.c.o CMakeFiles/parBrainSim.dir/src/solver.c.o CMakeFiles/parBrainSim.dir/src/brain.c.o CMakeFiles/parBrainSim.dir/src/matops.c.o CMakeFiles/parBrainSim.dir/src/nvu.c.o CMakeFiles/parBrainSim.dir/src/adjacency.c.o CMakeFiles/parBrainSim.dir/src/diffusion.c.o -o parBrainSim -rdynamic -lmpi_cxx -lmpi -lcxsparse -lm
In actual fact MPI_LIBRARIES
is deprecated and should be replaced by MPI_<lang>_LIBRARY
in our case <lang>
should be C
.
Thank you, @kiwifb. I'll get onto this shortly, to get the CMakeLists.txt straightened out. :)
Compile and link with C++ compiler.
Is there a reason to leave source files as .c instead of .cpp?