I'm quite new here, but there's a problem that needs solution. I think the title says exactly what I want to do. I need to use C for a reason I don't think is this important to mention. I tried searching Google, and found the same solution on most of the results.
After some searching I made a test application using solutions I found... but I can't get it working, I get a linker error.
If it's important: I'm using GCC 4.2.4 on a Linux.

Now some code...


#include <stdio.h>
#include "wrp.h"

int main(){


#ifdef __cplusplus
extern "C"
void wrp();


#include <iostream>
#include "wrp.h"

extern "C" void wrp(){
     std::cout << "wrapper zakonczyl dzialanie!\n";

Linker error I get:

/tmp/cc6Irctr.o: In function `main':
main.c:(.text+0x1e): undefined reference to `wrp'
collect2: ld returned 1 exit status

Command I use: gcc main.c -o test

Thanks in advance for Your help.

PS. I don't know if this thread belongs to C or C++ forum.

Recommended Answers

g++ -c cppcode.cpp
gcc -c main.c
g++ -o test main.o cppcode.o

Oh, and that might not work either.

This is how to mix C and C++
In particular, the main() needs …

Jump to Post

All 2 Replies

It worked! I can't believe it was so simple :)


wrapper zakonczyl dzialanie!

Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.