[Cmake] How to force linking with C++ compiler given C code?
Andy Cedilnik
andy . cedilnik at kitware . com
Thu, 18 Dec 2003 13:36:52 -0500
Hi Doug,
Try the following:
echo "" > foo.cxx
and then change
ADD_EXECUTABLE(hello_prog main.c foo.cxx)
I think that is the only way for now. Can you add a bug to the bug
tracker?
Andy
On Thu, 2003-12-18 at 13:25, Douglas Gregor wrote:
> Greetings,
> I'm trying to link an executable (compiled entirely from C sources) to a C++
> library using CMake under Linux. When the library is a shared library, there
> are no problems (of course). When trying to link statically, the generated
> makefile uses "gcc" instead of "g++", causing undefined symbols when
> referring to, e.g., std::cout.
> Here's one way to reproduce the problem (CMake 1.8.1, GCC 3.2.3, glibc
> 2.3.2):
>
> ------------CMakeLists.txt is:
> ADD_LIBRARY(hello_library hello.cpp)
> ADD_EXECUTABLE(hello_prog main.c)
> TARGET_LINK_LIBRARIES(hello_prog hello_library)
>
> ------------hello.cpp is:
> #include <iostream>
> extern "C" {
> void hello() { std::cout << "Hello, World!" << std::endl; }
> }
>
> ------------main.c is:
> void hello();
>
> int main()
> {
> hello();
> return 0;
> }
>
> Is there any way to request that hello_prog be linked as if it were C++ code?
>
> Thanks,
> Doug
>
> _______________________________________________
> Cmake mailing list
> Cmake at www . cmake . org
> http://www . cmake . org/mailman/listinfo/cmake