By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,351 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,351 IT Pros & Developers. It's quick & easy.

Compiling LGPL C source in Visual C++ FILE vs. Cfile?

P: n/a
Had a recent opportunity to grab some MP2 audio encoder source to use
in a little utility I am writing in support of a Korg portable
multitrack digital recorder. It is LGPL C and my project is Visual
C++. A few problems, e.g.

variables using C++ keywords, e.g. new and class - OK that was easily
solved.

biggest problem is file I/O, the C code uses lots of

FILE *fp;

fp = fopen("googble.mp2","rb);

etc.

Do I really have to go thru all the code and say CFile fp;
fp.Open(etc.etc.), or is there some way to get the original FILE
pointer method to work? I just get compile errors whenever this is
encountered.

For the record I write a computer program every 2 or 3 years so I am
pretty rusty on what may be a simple problem. I hope.

I am a bit daunted because FILE and associated routines are used ALL
over this code, and given it is open source I'd like to avoid major
mods if possible.

Thanks,

Gary
Jul 19 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a

"Gary" <fa***********@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
Had a recent opportunity to grab some MP2 audio encoder source to use
in a little utility I am writing in support of a Korg portable
multitrack digital recorder. It is LGPL C and my project is Visual
C++. A few problems, e.g.

variables using C++ keywords, e.g. new and class - OK that was easily
solved.

biggest problem is file I/O, the C code uses lots of

FILE *fp;

fp = fopen("googble.mp2","rb);

etc.

Do I really have to go thru all the code and say CFile fp;
fp.Open(etc.etc.), or is there some way to get the original FILE
pointer method to work? I just get compile errors whenever this is
encountered.

For the record I write a computer program every 2 or 3 years so I am
pretty rusty on what may be a simple problem. I hope.

I am a bit daunted because FILE and associated routines are used ALL
over this code, and given it is open source I'd like to avoid major
mods if possible.


Leave the code alone. Visual C++ is capable of compiling
in 'C mode'. Don't try to 'translate' to C++, you're just
asking for trouble. If I recall correctly, all you need
is a .c extension on your source file to make VC++ compile
as C instead of C++. See your documentation.

-Mike
Jul 19 '05 #2

P: n/a
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<Vr*****************@newsread3.news.pas.earth link.net>...
Leave the code alone. Visual C++ is capable of compiling
in 'C mode'. Don't try to 'translate' to C++, you're just
asking for trouble. If I recall correctly, all you need
is a .c extension on your source file to make VC++ compile
as C instead of C++. See your documentation.

-Mike


Mike, what I forgot to mention is that I'm incorporating this code
into a Visual C++ project that already IS in C++. I read some
articles on mixing C and C++ code which suggested that converting all
C source to C++ might be easier. The interface between the C++ code
and the MP2 encoder can, however, be limited to about 6 function
calls.

I know that C++ when it generates labels goes way beyond what a C
compiler would do... any handy hints on calling C code from within a
C++ program? E.g. I don't know whether I can compile a set of obj
files as C, another set as C++ and link them all together, or should I
make a dll for the C code, or a static library, etc. etc.

Thanks for any hints!

Gary
Jul 19 '05 #3

P: n/a
Gary wrote:

Mike, what I forgot to mention is that I'm incorporating this code
into a Visual C++ project that already IS in C++. I read some
articles on mixing C and C++ code which suggested that converting all
C source to C++ might be easier.


As you've seen, that's not necessarily true. It's often better to not
mess with working code.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 19 '05 #4

P: n/a

Gary wrote:
[...]
make a dll for the C code, or a static library, etc. etc.


Static library is, in effect, prohibited by brain-damaged LGPL (unless
you're quite happy to infect your own work). DLL is your only practical
choice... and, BTW, you might STILL be in violation of LGPL silliness.
I suggest that you should rather boycott the [L]GPL'd stuff if you can.

Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
and technically sound reciprocity provision (aka "share alike").

regards,
alexander.
Jul 19 '05 #5

P: n/a
Alexander Terekhov wrote:
Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
and technically sound reciprocity provision (aka "share alike").


What does this actually mean?

--
WW aka Attila
Jul 19 '05 #6

P: n/a

White Wolf wrote:

Alexander Terekhov wrote:
Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
and technically sound reciprocity provision (aka "share alike").


What does this actually mean?


Linking with libraries (aggregating components) doesn't create a
derivative work. It creates a collective work. Its constituent
parts can be distributed together ("static linking") or separately
("dynamic linking"). Non-[L]GPL "share alike" licenses do NOT try
to exercise the right to control the distribution of collective
works based on the "share alike"-licensed stuff. Fair and *non*-
discriminating "share alike" is basically the following:

http://creativecommons.org/licenses/by-sa/1.0/legalcode

see section 4.

<quote>

The above applies to the Work as incorporated in a Collective
Work, but this does not require the Collective Work apart from
the Work itself to be made subject to the terms of this License.

</quote>

and

<quote>

The above applies to the Derivative Work as incorporated in a
Collective Work, but this does not require the Collective Work
apart from the Derivative Work itself to be made subject to the
terms of this License.

</quote>

And, BTW, [L]GPL silliness is nicely illustrated here:

http://gcc.gnu.org/onlinedocs/libstd...o/license.html

regards,
alexander.
Jul 19 '05 #7

P: n/a
"White Wolf" <wo***@freemail.hu> writes:
Alexander Terekhov wrote:
Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
and technically sound reciprocity provision (aka "share alike").


What does this actually mean?


It means Terekhov is completely off-topic.
Jul 19 '05 #8

P: n/a
Sorry I earlier posted a stupid question answered in the FAQ.

The approach I will try is to compile the C code as-is to a static
LIB.

Then link to this from my VC++ code.

Header file will contain references to functions in the LIB as 'extern
"C" f(...)' etc.

If that doesn't work I'll be back!
Jul 19 '05 #9

P: n/a
Sorry I earlier posted a stupid question answered in the FAQ.

The approach I will try is to compile the C code as-is to a static
LIB.

Then link to this from my VC++ code.

Header file will contain references to functions in the LIB as 'extern
"C" f(...)' etc.

If that doesn't work I'll be back!
Jul 19 '05 #10

P: n/a

llewelly wrote:

"White Wolf" <wo***@freemail.hu> writes:
Alexander Terekhov wrote:
Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
and technically sound reciprocity provision (aka "share alike").


What does this actually mean?


It means Terekhov is completely off-topic.


A sort of "technical" aspects of C++ code licensing (ability to
use AND distribute collective works including both closed-source
and "share alike" libraries/components/parts) is completely *ON*
topic here.

regards,
alexander.
Jul 19 '05 #11

P: n/a
"Gary" <fa***********@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<Vr*****************@newsread3.news.pas.earth link.net>...
Leave the code alone. Visual C++ is capable of compiling
in 'C mode'. Don't try to 'translate' to C++, you're just
asking for trouble. If I recall correctly, all you need
is a .c extension on your source file to make VC++ compile
as C instead of C++. See your documentation.

-Mike


Mike, what I forgot to mention is that I'm incorporating this code
into a Visual C++ project that already IS in C++.


C and C++ can be linked together, with some 'help' at
the source code level.
I read some
articles

Which articles? Many if not most available literature about
C++, especially on the 'net, is poor quality if not simply
incorrect.
on mixing C and C++ code which suggested that converting all
C source to C++ might be easier.

"Might" is often a long way from "is." :-) With certain scenarios,
that advice might :-) be valid, but I recommend against
taking it as a 'general' rule. One of my 'guiding principles'
is the less code you need to touch, the less you will break. :-)
The interface between the C++ code
and the MP2 encoder can, however, be limited to about 6 function
calls.

I know that C++ when it generates labels goes way beyond what a C
compiler would do...
Name mangling.
any handy hints on calling C code from within a
C++ program?
Look up:

extern "C"
E.g. I don't know whether I can compile a set of obj
files as C, another set as C++ and link them all together,
Yes, you can.
or should I
make a dll
A DLL won't help with your questions.
for the C code, or a static library,
A library won't help with your questions (but might make
life easier for builds once you get the source code straightened out.)
etc. etc.

Thanks for any hints!

// cfile.c -- compile as C
#include <stdio.h>
void foo(void)
{
puts("Hello");
}

// cdecls.h -- #include in cpp file below

extern "C"
{
void foo(void);
}
// (This could have been done directly in cpp file below,
// but this way retains 'modularity' and allows for
// better control when adding more declarations, and
// doesn't clutter up the main code with 'messy details'.


// cppfile.cpp -- compile as C++

#include "cdecls.h"

int main()
{
foo();
return 0;
}

Linker should be able to resolve names.

-Mike

Jul 19 '05 #12

P: n/a
Alexander Terekhov wrote:
[SNIP]
And, BTW, [L]GPL silliness is nicely illustrated here:

http://gcc.gnu.org/onlinedocs/libstd...o/license.html


Danke!

--
WW aka Attila
Jul 19 '05 #13

P: n/a
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<ax*****************@newsread3.news.pas.earth link.net>...
"Gary" <fa***********@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
I read some
articles

Which articles? Many if not most available literature about
C++, especially on the 'net, is poor quality if not simply
incorrect.


Marshall Cline's C++ FAQ Lite, I got the impression that some in this
NG view it as some sort of holy reference?

Anyway I know that each situation is unique and I will probably waste
a fair amount of time finding the right solution. This is what I get
for NOT being a professional programmer and forgetting a lot of stuff
in between writing programs.
any handy hints on calling C code from within a
C++ program?


Look up:

extern "C"


I thank you for your detailed and lenghty reply. I'll let you know
how it goes.
Jul 19 '05 #14

P: n/a
"Gary" <fa***********@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<ax*****************@newsread3.news.pas.earth link.net>...
"Gary" <fa***********@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
I read some
articles

Which articles? Many if not most available literature about
C++, especially on the 'net, is poor quality if not simply
incorrect.


Marshall Cline's C++ FAQ Lite, I got the impression that some in this
NG view it as some sort of holy reference?


I and most consider it to be quality C++ literature, as well
as is the hardcopy book form, which covers much more material.
I'd stop short of calling it 'holy' however (except perhaps
when it evokes a "holy sh*t!' I didn't know that!" :-) )

I was only warning you about the plethora of wrong information
that is out there on the web. You apparently are already
cautious enough to filter the material before relying upon it.


Anyway I know that each situation is unique
Each specific one, yes. But what you're asking about
(linking C++ code with C), is quite common.
and I will probably waste
a fair amount of time finding the right solution.
The right solution is to use extern "C"
No need to waste any more time.

This is what I get
for NOT being a professional programmer and forgetting a lot of stuff
in between writing programs.
It's no crime to practice programming as a hobby instead
of a profession. And even as a professional, I often
forget things too, which is why I always keep reference
material close at hand.
any handy hints on calling C code from within a
C++ program?

What I showed you should be all you need.

Look up:

extern "C"


I thank you for your detailed and lenghty reply. I'll let you know
how it goes.


Good luck!

-Mike
Jul 19 '05 #15

P: n/a
On Thu, 18 Sep 2003 19:59:52 +0200, Alexander Terekhov
<te******@web.de> wrote in comp.lang.c++:

llewelly wrote:

"White Wolf" <wo***@freemail.hu> writes:
Alexander Terekhov wrote:
> Academic style licensing (BSD/MIT/AFL/etc.) aside for a moment, stick
> with OFL'd/IPL'd/CPL'd/and-alike-'d stuff with fair and both legally
> and technically sound reciprocity provision (aka "share alike").

What does this actually mean?


It means Terekhov is completely off-topic.


A sort of "technical" aspects of C++ code licensing (ability to
use AND distribute collective works including both closed-source
and "share alike" libraries/components/parts) is completely *ON*
topic here.


....if and only if you can provide a citation from the ISO C++ standard
that defines any of the following:

"licensing"
"distribute"
"closed-source"
"collective works"
"components"
"parts"

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 19 '05 #16

P: n/a

Jack Klein wrote:
[...]
and "share alike" libraries/components/parts) is completely *ON*
topic here.


...if and only if you can provide a citation from the ISO C++ standard


Says who? I reasonably consider it "of general interest to the worldwide
C++ community" and THAT makes it "on-topic" even on c.l.c++.mod, buddy.

regards,
alexander.
Jul 19 '05 #17

P: n/a
Alexander Terekhov wrote:
Jack Klein wrote:
[...]
and "share alike" libraries/components/parts) is completely *ON*
topic here.


...if and only if you can provide a citation from the ISO C++
standard


Says who? I reasonably consider it "of general interest to the
worldwide C++ community" and THAT makes it "on-topic" even on
c.l.c++.mod, buddy.


Making friends again? ;-) BTW c.l.c++.mod is less restrictive than this
newsgroup. :-)

--
Attila aka WW
Jul 19 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.