how to call extern variables from a C library...

N

Noel Mosa

Hi,
i am using a library compiled in C(FFMPEG) and need to access a number
of variables that are defined within a C module.
The include file for the library declares it as a extern pointer.
I can compile without problems but when linking the linker cant find it
and aborts.

lets say a variable is called "dummy" then the linker gives an error
that it cant find "_dummy".
The variable extern declaration is already within "extern "C ""
brackets...(wich are again within #ifdef __cplusplus'es)
or is maybe the problem that it is also a extern variable?
so the declaration looks like
extern "C" extern int dummy;


what can i dooo?? is it a thing i can resolve in the language or do i
have to tweak the linker?
thanks for any hint or response!!
 
V

Victor Bazarov

Noel said:
i am using a library compiled in C(FFMPEG) and need to access a number
of variables that are defined within a C module.
The include file for the library declares it as a extern pointer.
I can compile without problems but when linking the linker cant find
it and aborts.

Linker issues are compiler- and platform-specific. Most likely they
cannot be resolved using C++ language means.
lets say a variable is called "dummy" then the linker gives an error
that it cant find "_dummy".

Do you provide the module in which that variable is *defined* to the
linker?
The variable extern declaration is already within "extern "C ""
brackets...(wich are again within #ifdef __cplusplus'es)
or is maybe the problem that it is also a extern variable?
so the declaration looks like
extern "C" extern int dummy;


what can i dooo?? is it a thing i can resolve in the language or do i
have to tweak the linker?

I am not sure what "tweak the linker" means. What can you tweak in
your linker? Isn't it just a program which you run?

V
 
N

Noel Mosa

Hi, thanks for the quick response,
Do you provide the module in which that variable is *defined* to the
linker?
like i said it is a already compiled library. I do provide the "lib"
files though. I also have the source code but the program is linked
against the libs.


I am not sure what "tweak the linker" means. What can you tweak in
your linker? Isn't it just a program which you run?

I meant for example adding options or switches...
Maybe theres a switch that tells the linker something like:
"Hey buddy, the variable is declared in the library i gave you! look in
there!"

I am writing this in visual studio and am going to ask in that group too.

So do you think, from the language point of view, declaring the variable as:
extern "C" extern someClasstype dummy*;

is enough?
 
V

Victor Bazarov

Noel said:
Hi, thanks for the quick response,

like i said it is a already compiled library. I do provide the "lib"
files though. I also have the source code but the program is linked
against the libs.

Unfortunately it's a problem outside of the _language_ area of concern.
Libraries are platform- and compiler-specific.
I meant for example adding options or switches...

We don't know about those. C++ doesn't define them (I don't mean to
sound dismissive but that's just how it is).
Maybe theres a switch that tells the linker something like:
"Hey buddy, the variable is declared in the library i gave you! look
in there!"

Maybe. In most cases, a reference to that variable and the extern
declaration should be sufficient so that the compiler produces certain
instructions to the linker what needs to be resolved, and then you
give the linker enough information as to where to find those objects.

It sounds like you have done all that.
I am writing this in visual studio and am going to ask in that group
too.

Good idea.
So do you think, from the language point of view, declaring the
variable as: extern "C" extern someClasstype dummy*;

is enough?

Well, yes. Only it should probably be

extern "C" someClasstype* dummy;

V
 
B

benben

I meant for example adding options or switches...
Maybe theres a switch that tells the linker something like:
"Hey buddy, the variable is declared in the library i gave you! look in
there!"

I am writing this in visual studio and am going to ask in that group too.

That's the right thing to do. Unfortunately the C++ standards committee
doesn't standardize anything but the language. Visual studio is not part
of the standard, compiler and linker switches are not part of the
standard. Platform specific issues are not part of the standard.

And here people only respond to things that the standard concerns.
So do you think, from the language point of view, declaring the variable as:
extern "C" extern someClasstype dummy*;

is enough?

Maybe. But usually we #include the header provided by the library and
RTM on how to use the lib.

Regards,
Ben
 
D

David W

Victor Bazarov said:
I am not sure what "tweak the linker" means. What can you tweak in
your linker? Isn't it just a program which you run?

Well, I did tweak my linker once. It was calculating a negative 32-bit address wrongly, and I found
out where by running it under a debugger and telling it to stop when the CPU's EAX register equalled
a specific address I'd planted in the program it was linking. After changing a SHR instruction
(shift right) in the linker's executable code to SAR (shift arithmetic right), it linked the program
correctly.

DW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top