Thread: compiling c program with C++ program

  1. #1
    Registered User
    Join Date
    Jul 2017
    Posts
    13

    compiling c program with C++ program

    Hello,
    I have C++ progam that compiles and running well. Now I need to test one feature with c program.

    In c program, I am writing one client_wrapper.h and client_wrapper.c file.
    In the client_wrapper.h file.
    Code:
    #ifdef __cplusplus
    extern "C" {
    #endif 
    
    char* get_msg()
    
    #ifdef __cplusplus
    }
    #endif
    In c file, without any decoration, I implement logic in client_wrapper.c fie.

    In my cpp program, I wrote at the begining,
    Code:
    extern "C" {
    char* get_msg()
    }
    
    ..........in the code I called get_msg().
    
    ...............
    now I'm facing linking problem. Compilion went well and linking is not working.
    Why? where is problem. I am g++ 5.4.0.

    Thanks
    Sothy

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Why did you not post the link error?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jul 2017
    Posts
    13
    error msg
    Code:
    [
    1/1] LINK (stripped) build/release/sx_main_server
    FAILED: g++  -O2 `pkg-config --cflags --libs /home/sothy/seastar/build/release/seastar.pc`   -g -Wl,--no-as-needed   -fvisibility=hidden  -pthread -lstdc++  -o  build/release/sx_main_server build/sx_main_server.o   
    build/sx_main_server.o: In function `udp_server::start(unsigned short)::{lambda()#2}::operator()() const::{lambda(seastar::net::udp_datagram)#1}::operator()(seastar::net) const':
    /home/sothy/seastar/apps/udpd/udp_server.hh:72: undefined reference to `get_msg'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Any reason you are not linking to client_wrapper.o because that is what is likely causing the error?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program is compiling, but not doing what I want it to
    By charms26 in forum C Programming
    Replies: 3
    Last Post: 10-24-2015, 10:31 AM
  2. Please help with compiling a program
    By Baxter Stockman in forum C Programming
    Replies: 7
    Last Post: 10-18-2015, 03:48 PM
  3. Can somebody tell me why this program isn't compiling?
    By caduardo21 in forum Windows Programming
    Replies: 2
    Last Post: 01-25-2005, 08:40 AM
  4. Help compiling a program
    By jjj93421 in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2004, 06:38 PM
  5. Compiling a program in VC++ and run it in DOS
    By Willhunting in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-18-2003, 04:09 AM

Tags for this Thread