Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no extern "C" into ocaml C-stub headers #5467

Closed
vicuna opened this issue Jan 6, 2012 · 2 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Jan 6, 2012

Original bug ID: 5467
Reporter: testcocoon
Assigned to: meyer
Status: closed (set by @xavierleroy on 2013-08-31T10:44:10Z)
Resolution: duplicate
Priority: normal
Severity: minor
Platform: Godi
OS: Linux
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Duplicate of: #4963

Bug description

When creating a binding to C++ code it is necessary to compile against a C++ compiler (ex g++).
in this case using caml_copy_string() function produces a linker issue:
llvmex_ocaml.o: In function llvmex_get_as_string': llvmex_ocaml.c:(.text+0x127): undefined reference to caml_copy_string(char const*)'

The problem is due to the fact that caml_copy_string is seen as C++ symbol (not as C symbol).
To correct the issue it is necessary to put extern "C" around the ocaml headers:
extern "C" {
#include "caml/alloc.h"
#include "caml/custom.h"
#include "caml/memory.h"
#include "caml/fail.h"
#include "caml/callback.h"
}

In my opinion this should not be the case. It would be better that the headers starts with:
#ifdef __cplusplus
extern "C" {
#endif

and ends with:
#ifdef __cplusplus
}
#endif

To enable the possibility to use it in C and C++.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 6, 2012

Comment author: meyer

Sorry a bit tired today, I thought i changed to resolve by mistake, now I see it's a dupe

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 6, 2012

Comment author: @protz

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.