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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary

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

    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
  • Mike Wahler

    #2
    Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?


    "Gary" <faultline1989@ yahoo.com> wrote in message
    news:87dac912.0 309172139.1ffcb 8a5@posting.goo gle.com...[color=blue]
    > 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.[/color]

    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


    Comment

    • Gary

      #3
      Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

      "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message news:<Vrcab.727 0$UN4.3812@news read3.news.pas. earthlink.net>. ..[color=blue]
      > 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[/color]

      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

      Comment

      • Pete Becker

        #4
        Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

        Gary wrote:[color=blue]
        >
        > 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.[/color]

        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)

        Comment

        • Alexander Terekhov

          #5
          Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?


          Gary wrote:
          [...][color=blue]
          > make a dll for the C code, or a static library, etc. etc.[/color]

          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.

          Comment

          • White Wolf

            #6
            Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

            Alexander Terekhov wrote:[color=blue]
            > 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").[/color]

            What does this actually mean?

            --
            WW aka Attila


            Comment

            • Alexander Terekhov

              #7
              Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?


              White Wolf wrote:[color=blue]
              >
              > Alexander Terekhov wrote:[color=green]
              > > 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").[/color]
              >
              > What does this actually mean?[/color]

              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:



              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:



              regards,
              alexander.

              Comment

              • llewelly

                #8
                Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                "White Wolf" <wolof@freemail .hu> writes:
                [color=blue]
                > Alexander Terekhov wrote:[color=green]
                > > 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").[/color]
                >
                > What does this actually mean?[/color]

                It means Terekhov is completely off-topic.

                Comment

                • Gary

                  #9
                  Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                  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!

                  Comment

                  • Gary

                    #10
                    Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                    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!

                    Comment

                    • Alexander Terekhov

                      #11
                      Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?


                      llewelly wrote:[color=blue]
                      >
                      > "White Wolf" <wolof@freemail .hu> writes:
                      >[color=green]
                      > > Alexander Terekhov wrote:[color=darkred]
                      > > > 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").[/color]
                      > >
                      > > What does this actually mean?[/color]
                      >
                      > It means Terekhov is completely off-topic.[/color]

                      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.

                      Comment

                      • Mike Wahler

                        #12
                        Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                        "Gary" <faultline1989@ yahoo.com> wrote in message
                        news:87dac912.0 309180735.7c8ed ac1@posting.goo gle.com...[color=blue]
                        > "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message[/color]
                        news:<Vrcab.727 0$UN4.3812@news read3.news.pas. earthlink.net>. ..[color=blue][color=green]
                        > > 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[/color]
                        >
                        > Mike, what I forgot to mention is that I'm incorporating this code
                        > into a Visual C++ project that already IS in C++.[/color]

                        C and C++ can be linked together, with some 'help' at
                        the source code level.
                        [color=blue]
                        > I read some
                        > articles[/color]


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


                        "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. :-)
                        [color=blue]
                        >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...[/color]

                        Name mangling.
                        [color=blue]
                        >any handy hints on calling C code from within a
                        > C++ program?[/color]

                        Look up:

                        extern "C"
                        [color=blue]
                        >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,[/color]

                        Yes, you can.
                        [color=blue]
                        >or should I
                        > make a dll[/color]

                        A DLL won't help with your questions.
                        [color=blue]
                        >for the C code, or a static library,[/color]

                        A library won't help with your questions (but might make
                        life easier for builds once you get the source code straightened out.)
                        [color=blue]
                        >etc. etc.
                        >
                        > Thanks for any hints![/color]


                        // 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



                        Comment

                        • White Wolf

                          #13
                          Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                          Alexander Terekhov wrote:
                          [SNIP][color=blue]
                          > And, BTW, [L]GPL silliness is nicely illustrated here:
                          >
                          > http://gcc.gnu.org/onlinedocs/libstd...o/license.html[/color]

                          Danke!

                          --
                          WW aka Attila


                          Comment

                          • Gary

                            #14
                            Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                            "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message news:<axmab.768 7$UN4.5091@news read3.news.pas. earthlink.net>. ..[color=blue]
                            > "Gary" <faultline1989@ yahoo.com> wrote in message
                            > news:87dac912.0 309180735.7c8ed ac1@posting.goo gle.com...
                            >[color=green]
                            > > I read some
                            > > articles[/color]
                            >
                            >
                            > Which articles? Many if not most available literature about
                            > C++, especially on the 'net, is poor quality if not simply
                            > incorrect.[/color]

                            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.
                            [color=blue][color=green]
                            > >any handy hints on calling C code from within a
                            > > C++ program?[/color]
                            >
                            > Look up:
                            >
                            > extern "C"
                            >[/color]

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

                            Comment

                            • Mike Wahler

                              #15
                              Re: Compiling LGPL C source in Visual C++ FILE vs. Cfile?

                              "Gary" <faultline1989@ yahoo.com> wrote in message
                              news:87dac912.0 309181602.15531 7f9@posting.goo gle.com...[color=blue]
                              > "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message[/color]
                              news:<axmab.768 7$UN4.5091@news read3.news.pas. earthlink.net>. ..[color=blue][color=green]
                              > > "Gary" <faultline1989@ yahoo.com> wrote in message
                              > > news:87dac912.0 309180735.7c8ed ac1@posting.goo gle.com...
                              > >[color=darkred]
                              > > > I read some
                              > > > articles[/color]
                              > >
                              > >
                              > > Which articles? Many if not most available literature about
                              > > C++, especially on the 'net, is poor quality if not simply
                              > > incorrect.[/color]
                              >
                              > Marshall Cline's C++ FAQ Lite, I got the impression that some in this
                              > NG view it as some sort of holy reference?[/color]

                              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.

                              [color=blue]
                              >
                              > Anyway I know that each situation is unique[/color]

                              Each specific one, yes. But what you're asking about
                              (linking C++ code with C), is quite common.
                              [color=blue]
                              >and I will probably waste
                              > a fair amount of time finding the right solution.[/color]

                              The right solution is to use extern "C"
                              No need to waste any more time.

                              [color=blue]
                              >This is what I get
                              > for NOT being a professional programmer and forgetting a lot of stuff
                              > in between writing programs.[/color]

                              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.
                              [color=blue]
                              >[color=green][color=darkred]
                              > > >any handy hints on calling C code from within a
                              > > > C++ program?[/color][/color][/color]

                              What I showed you should be all you need.
                              [color=blue][color=green]
                              > >
                              > > Look up:
                              > >
                              > > extern "C"
                              > >[/color]
                              >
                              > I thank you for your detailed and lenghty reply. I'll let you know
                              > how it goes.[/color]

                              Good luck!

                              -Mike


                              Comment

                              Working...