Thread: Complie and link C++ code in C

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715

    Complie and link C++ code in C

    Hello people,
    it's been a long since last time I worked with C and C++. Is it possible to link Cpp code in C?
    What I mean is this:
    In basics, it comes to this...

    I have two files:
    Test_cpp.h
    Code:
    int test_cpp(int);
    Test_cpp.cpp
    Code:
    int test_cpp(int x)
    {
        return x+2;
    }
    and main.c /*in other C project in which Test_cpp.h and Test_cpp.cpp are included*/
    Code:
    #include <stdio.h>
    #include "Test_CPP.h"
    
    int main(int argc, char *argv[])
    {
      printf("&#37;d", test_cpp(4));
      return 0;
    }
    Is it possible to use extern keyword to make this work?

    Thanks
    Last edited by Micko; 02-26-2008 at 12:00 PM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed