1

I want to use my school custom library in a C++ project but the library linking seems not working... When I create my program in C and I try to compile it, it work...

See by yourself:

gcc like it but not g++

I think that the X11 and/or Xext libraries dependencies of the Mlx are in cause, there can be some

#if __cplusplus

    void    *x11_mlx_function_wanted(void);

#endif

I had already check if the mlx contains some check like that and I saw nothing.

Thank you in advance

EDIT

And I succeed in objective-c.

Kerollmops
  • 303
  • 4
  • 15
  • 1
    Please do not post graphics if you also can post the text of the error messages. Nobody can copy any code to compile it and your messages waste a lot of space. So please send text if possible. – Klaus Dec 13 '14 at 19:38
  • I want to post this: http://stackoverflow.com/a/18879053/1941280 And I want to die to... Oooops, @Klaus sorry... – Kerollmops Dec 13 '14 at 22:04

1 Answers1

1

The problem is C++ name-mangling. If you declare a function in C11, it ends up with a "mangled" name, which encodes the namespace and the types of the arguments. That's necessary because in C++, various overloads can exist for the same function name. The overloads are independent functions; they do not even have to be in the same object library.

In the object library itself, the functions will have ordinary C names. But since the header file is processed with a C++ compiler, the declared functions will be named as though they were C++ functions.

One possible solution might be to declare all the included functions to be C functions:

extern "C" {
  #include "/usr/X11/include/mlx.h"
}
rici
  • 234,347
  • 28
  • 237
  • 341