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

G

Gary

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
 
M

Mike Wahler

Gary said:
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
 
G

Gary

Mike Wahler said:
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
 
P

Pete Becker

Gary said:
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.
 
A

Alexander Terekhov

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.
 
W

White Wolf

Alexander said:
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?
 
A

Alexander Terekhov

White said:
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/libstdc++/17_intro/license.html

regards,
alexander.
 
G

Gary

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!
 
G

Gary

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!
 
A

Alexander Terekhov

llewelly said:
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.
 
M

Mike Wahler

Gary said:
"Mike Wahler" <[email protected]> wrote in message

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
 
G

Gary

Mike Wahler said:
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.
Look up:

extern "C"

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

Mike Wahler

Gary said:
"Mike Wahler" <[email protected]> wrote in message

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.

What I showed you should be all you need.
I thank you for your detailed and lenghty reply. I'll let you know
how it goes.

Good luck!

-Mike
 
J

Jack Klein

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
 
A

Alexander Terekhov

Jack Klein wrote:
[...]
...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.
 
A

Attila Feher

Alexander said:
Jack Klein wrote:
[...]
...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. :)
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top