473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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!!
Oct 11 '06 #1
5 2495
Noel Mosa wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 11 '06 #2
Hi, thanks for the quick response,
>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?
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?
Oct 11 '06 #3
Noel Mosa wrote:
Hi, thanks for the quick response,
>>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?
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 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...
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 11 '06 #4
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
Oct 11 '06 #5
"Victor Bazarov" <v.********@comAcast.netwrote in message news:eg**********@news.datemas.de...
>
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
Oct 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cameron | last post by:
I'm looking to use the system (or exec) function to call a shell script in UNIX. The following is the UNIX command line without PHP: /home/public_html/VariableDirectory/myScript.ksh ...
0
by: Thys Meintjes | last post by:
Hi All, I've inherited a c library and is the process of wrapping it using Pyrex. The library code is a state machine and remembers previous values in order to determine new values on, for...
2
by: Dave | last post by:
Why does the program below link successfully? (Yep, what's shown is all there is to it.) Does an extern variable actually have to be referenced to be bound to an address? Is this...
2
by: Paul M | last post by:
Hi, This is on an AS/400 which can be a little strange but I think the basic question is portable. I have a (non-C) program that needs to make series of calls to some C programs/functions....
3
by: dotNETDavid | last post by:
We've broken our app into various assemblies. The WinForm assembly provides the user interface, other assemblies provide various I/O services. I'd like to be able to call...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: hendyhanusin | last post by:
Dear all, Pls help in JavaScript coding since i'm a beginner in JavaScript . i have a .NET class library (DLL) : ACR120DLL.ACR120DLL... Does anybody know how to use this DLL event (AddList,...
7
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am trying to see if I can call a Library remotely. The library contains a Form that I want to display then pass back some data to user that called this form remotely. I have it working...
1
by: SteveM | last post by:
I suspect that this is either not possible or really really tricky, but need to ask. We have a great deal of work done in perl in our environment, and we are currently starting to do more work with...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.