compile errors. pls help

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

    compile errors. pls help

    Hi,

    I am really not good at c/c++.
    Some simple code..


    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "simlibdefs .h"


    extern int *list_rank, *list_size; /// this is the line 6
    extern int maxatr, maxlist, next_event_type ;
    extern double *transfer, sim_time, prob_distrib[26];
    extern struct master {
    double *value;
    struct master *pr;
    struct master *sr;



    } **head, **tail;


    /* Declare simlib functions. */
    ---

    when I compile this with other files, I got the error msg like this:


    simlib.h:6: error: expected init-declarator before "extern"
    simlib.h:6: error: expected `,' or `;' before "extern"


    I am using gcc to compile files...
    Thanks a lot,


    Beet


  • dj3vande@csclub.uwaterloo.ca.invalid

    #2
    Re: compile errors. pls help

    In article <dfe0b548-97a8-44fb-b1b9-91632b3e511c@k1 3g2000hse.googl egroups.com>,
    beet <whhggg@gmail.c omwrote:

    [...]
    >#include "simlibdefs .h"
    >
    >extern int *list_rank, *list_size; /// this is the line 6
    [...]
    >when I compile this with other files, I got the error msg like this:
    >
    >simlib.h:6: error: expected init-declarator before "extern"
    >simlib.h:6: error: expected `,' or `;' before "extern"



    dave

    --
    Dave Vandervies dj3vande at eskimo dot com
    I'm a bad driver. I miss things.
    No, no, bad drivers _hit_ things.
    --Richard Gadsden and Dan Birchall in the scary devil monastery

    Comment

    • Ian Collins

      #3
      Re: compile errors. pls help

      beet wrote:
      >
      #include <stdio.h>
      #include <stdlib.h>
      #include <math.h>
      #include "simlibdefs .h"
      >
      extern int *list_rank, *list_size; /// this is the line 6
      ---
      >
      when I compile this with other files, I got the error msg like this:
      >
      >
      simlib.h:6: error: expected init-declarator before "extern"
      simlib.h:6: error: expected `,' or `;' before "extern"
      >
      Your problem list not in the code you posted, but in the code you did not.

      Check simlibdefs.h for a missing bracket or #endif.

      --
      Ian Collins.

      Comment

      • Kenneth Brody

        #4
        Re: compile errors. pls help

        beet wrote:
        >
        Hi,
        >
        I am really not good at c/c++.
        Some simple code..
        >
        #include <stdio.h>
        #include <stdlib.h>
        #include <math.h>
        #include "simlibdefs .h"
        >
        extern int *list_rank, *list_size; /// this is the line 6
        extern int maxatr, maxlist, next_event_type ;
        extern double *transfer, sim_time, prob_distrib[26];
        extern struct master {
        double *value;
        struct master *pr;
        struct master *sr;
        >
        } **head, **tail;
        >
        /* Declare simlib functions. */
        ---
        >
        when I compile this with other files, I got the error msg like this:
        What do you mean "compile this with other files"?
        simlib.h:6: error: expected init-declarator before "extern"
        simlib.h:6: error: expected `,' or `;' before "extern"
        [...]

        Is this file simlib.h?

        What's in simlibdefs.h? I see this often when the last-included file
        isn't correct, leaving some dangling definition/declaration.

        --
        +-------------------------+--------------------+-----------------------+
        | Kenneth J. Brody | www.hvcomputer.com | #include |
        | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
        +-------------------------+--------------------+-----------------------+
        Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>

        Comment

        • Keith Thompson

          #5
          Re: compile errors. pls help

          beet <whhggg@gmail.c omwrites:
          On Apr 18, 4:26 pm, Kenneth Brody <kenbr...@spamc op.netwrote:
          >beet wrote:
          I am really not good at c/c++.
          Some simple code..
          >>
          #include <stdio.h>
          #include <stdlib.h>
          #include <math.h>
          #include "simlibdefs .h"
          >>
          extern int *list_rank, *list_size;    /// this is the line 6
          extern int maxatr, maxlist, next_event_type ;
          extern double  *transfer, sim_time, prob_distrib[26];
          extern struct master {
              double  *value;
              struct master *pr;
              struct master *sr;
          >>
          } **head, **tail;
          >>
          /* Declare simlib functions. */
          ---
          >>
          when I compile this with other files, I got the error msg like this:
          >>
          >What do you mean "compile this with other files"?
          >>
          simlib.h:6: error: expected init-declarator before "extern"
          simlib.h:6: error: expected `,' or `;' before "extern"
          [...]
          >Is this file simlib.h?
          >>
          >What's in simlibdefs.h?  I see this often when the last-included file
          >isn't correct, leaving some dangling definition/declaration.
          [...]
          >
          Thanks for the reply, the simlibdefs.h is listed:
          /* This is simlibdefs.h. */
          #ifndef _simlibdefs_
          #define _simlibdefs_
          [...]
          #endif
          [...]

          I see nothing wrong with your simlibdefs.h. I *see* nothing wrong
          with your other source file when I view it in my newsreader. However,
          a closer look at the article and its headers indicates that it's
          encoded as "quoted-printable". When I saved your article as a text
          file, I see several occurrences of "=A0", which is the
          quoted-printable encoding for the character 0xa0 or decimal 160, which
          is the "NO-BREAK SPACE" character in the ISO-8859-1 character set
          specified in your article's header. When I manually removed the "=A0"
          encodings, the code compiled without error.

          Whatever editor you used to create your C source file probably
          inserted these characters automatically for some reason. That would
          be fine if you were creating a text file intended to be printed or
          otherwise processed using software that understands the "NO-BREAK
          SPACE" character, but it's not a valid character in C. (Note: the
          fact that I saw "=A0" sequences rather than NO-BREAK SPACE control
          characters is probably an artifact of the way I saved the file; either
          will have about the same effect.)

          Find some way to replace these characters with ordinary spaces, and
          try to use an editor that's designed to work with source code.

          --
          Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • beet

            #6
            Re: compile errors. pls help

            On Apr 20, 5:15 pm, Keith Thompson <ks...@mib.orgw rote:
            beet <whh...@gmail.c omwrites:
            On Apr 18, 4:26 pm, Kenneth Brody <kenbr...@spamc op.netwrote:
            beet wrote:
            I am really not good at c/c++.
            Some simple code..
            >
            #include <stdio.h>
            #include <stdlib.h>
            #include <math.h>
            #include "simlibdefs .h"
            >
            extern int *list_rank, *list_size;    /// this is the line 6
            extern int maxatr, maxlist, next_event_type ;
            extern double  *transfer, sim_time, prob_distrib[26];
            extern struct master {
                double  *value;
                struct master *pr;
                struct master *sr;
            >
            } **head, **tail;
            >
            /* Declare simlib functions. */
            ---
            >
            when I compile this with other files, I got the error msg like this:
            >
            What do you mean "compile this with other files"?
            >
            simlib.h:6: error: expected init-declarator before "extern"
            simlib.h:6: error: expected `,' or `;' before "extern"
            [...]
            Is this file simlib.h?
            >
            What's in simlibdefs.h?  I see this often when the last-included file
            isn't correct, leaving some dangling definition/declaration.
            [...]
            >
            Thanks for the reply, the simlibdefs.h is listed:
            /* This is simlibdefs.h. */
            #ifndef _simlibdefs_
            #define _simlibdefs_
            [...]
            #endif
            >
            [...]
            >
            I see nothing wrong with your simlibdefs.h.  I *see* nothing wrong
            with your other source file when I view it in my newsreader.  However,
            a closer look at the article and its headers indicates that it's
            encoded as "quoted-printable".  When I saved your article as a text
            file, I see several occurrences of "=A0", which is the
            quoted-printable encoding for the character 0xa0 or decimal 160, which
            is the "NO-BREAK SPACE" character in the ISO-8859-1 character set
            specified in your article's header.  When I manually removed the "=A0"
            encodings, the code compiled without error.
            >
            Whatever editor you used to create your C source file probably
            inserted these characters automatically for some reason.  That would
            be fine if you were creating a text file intended to be printed or
            otherwise processed using software that understands the "NO-BREAK
            SPACE" character, but it's not a valid character in C.  (Note: the
            fact that I saw "=A0" sequences rather than NO-BREAK SPACE control
            characters is probably an artifact of the way I saved the file; either
            will have about the same effect.)
            >
            Find some way to replace these characters with ordinary spaces, and
            try to use an editor that's designed to work with source code.
            >
            --
            Keith Thompson (The_Other_Keit h) <ks...@mib.or g>
            Nokia
            "We must do something.  This is something.  Therefore, we must do this.."
                -- Antony Jay and Jonathan Lynn, "Yes Minister"- Hide quoted text -
            >
            - Show quoted text -
            Hi Keith,

            Thanks for your reply. I should post more info on my code.
            The simlib.c and simlib.h and simlibdefs.h themselves were good to
            compile
            and get an obj file. Once I tried to link simlib.o to another c++ obj
            getFunc.obj; I got the above errors. All these c/c++ code was supposed
            to link
            some Fortran code, using f90...

            so my simple makefile:

            #makefile for pvar search

            FF = f90
            GCC = gcc -Wall -g

            all: pvar

            mbsubs.o: mbsubs.for
            $(FF) -c mbsubs.for

            pbsubs.o: pbsubs.for
            $(FF) -c pbsubs.for

            tvar.o: tvar.for
            $(FF) -c tvar.for

            tbsubs.o: tbsubs.for
            $(FF) -c tbsubs.for

            pvar.o: pvar.for
            $(FF) -c pvar.for

            simlib.o: simlib.c simlib.h simlibdefs.h
            $(GCC) -c simlib.c

            getFunc.o: getFunc.cpp getFunc.h
            $(GCC) -c getFunc.cpp

            pvar: pvar.o mbsubs.o tvar.o tbsubs.o pbsubs.o getFunc.o simlib.o
            $(FF) -o pvar pvar.o mbsubs.o tvar.o tbsubs.o pbsubs.o
            getFunc.o simlib.o -L/opt/gcc/3.4.4/lib/ -lc -lstdc++


            ----

            Thanks again for your help.

            Beet

            Comment

            • Kenneth Brody

              #7
              Re: compile errors. pls help

              Keith Thompson wrote:
              [...]
              I see nothing wrong with your simlibdefs.h. I *see* nothing wrong
              with your other source file when I view it in my newsreader. However,
              a closer look at the article and its headers indicates that it's
              encoded as "quoted-printable". When I saved your article as a text
              file, I see several occurrences of "=A0", which is the
              quoted-printable encoding for the character 0xa0 or decimal 160, which
              is the "NO-BREAK SPACE" character in the ISO-8859-1 character set
              specified in your article's header. When I manually removed the "=A0"
              encodings, the code compiled without error.
              >
              Whatever editor you used to create your C source file probably
              inserted these characters automatically for some reason. That would
              be fine if you were creating a text file intended to be printed or
              otherwise processed using software that understands the "NO-BREAK
              SPACE" character, but it's not a valid character in C. (Note: the
              fact that I saw "=A0" sequences rather than NO-BREAK SPACE control
              characters is probably an artifact of the way I saved the file; either
              will have about the same effect.)
              [...]

              It may not be his text editor, but rather his newsreader. Note that
              my post contains no such "hidden" characters, yet the quoted parts
              of my post in his reply have replaced some spaces with "=A0"s.

              Which brings us back to what the actual problem may be. I would
              recommend, if possible, looking at the output of the preprocessor,
              and looking backwards from the line giving the error to see what is
              the "real" error.

              --
              +-------------------------+--------------------+-----------------------+
              | Kenneth J. Brody | www.hvcomputer.com | #include |
              | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
              +-------------------------+--------------------+-----------------------+
              Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


              Comment

              • Ben Bacarisse

                #8
                Re: compile errors. pls help

                beet <whhggg@gmail.c omwrites:
                On Apr 20, 5:15 pm, Keith Thompson <ks...@mib.orgw rote:
                >beet <whh...@gmail.c omwrites:
                <snip>
                >beet wrote:
                <snip>
                when I compile this with other files, I got the error msg like this:
                <snip>
                simlib.h:6: error: expected init-declarator before "extern"
                simlib.h:6: error: expected `,' or `;' before "extern"
                <snip>
                >...  However,
                >a closer look at the article and its headers indicates that it's
                >encoded as "quoted-printable".  When I saved your article as a text
                >file, I see several occurrences of "=A0",
                <snip>
                >--
                >Keith Thompson (The_Other_Keit h) <ks...@mib.or g>
                Please don't quote sig blocks.

                <snip>
                The simlib.c and simlib.h and simlibdefs.h themselves were good to
                compile
                and get an obj file. Once I tried to link simlib.o to another c++ obj
                getFunc.obj; I got the above errors.
                Sounds very unlikely. The "above errors" are compile-time errors,
                not link errors. If the errors originally shown are indeed still
                occurring (and Keith Thompson's diagnosis of the problem was no the
                issue) you need to post the actual code.

                --
                Ben.

                Comment

                • Keith Thompson

                  #9
                  Re: compile errors. pls help

                  beet <whhggg@gmail.c omwrites:
                  [...]
                  >beet wrote:
                  [...]
                  simlib.h:6: error: expected init-declarator before "extern"
                  simlib.h:6: error: expected `,' or `;' before "extern"
                  [...]
                  Hi Keith,
                  >
                  Thanks for your reply. I should post more info on my code.
                  The simlib.c and simlib.h and simlibdefs.h themselves were good to
                  compile
                  and get an obj file. Once I tried to link simlib.o to another c++ obj
                  getFunc.obj; I got the above errors. All these c/c++ code was supposed
                  to link
                  some Fortran code, using f90...
                  >
                  so my simple makefile:
                  >
                  #makefile for pvar search
                  >
                  FF = f90
                  GCC = gcc -Wall -g
                  [snip]

                  When you post a followup, it's rarely necessary to quote the entire
                  article to which you're replying. Quote only what's necessary for
                  your followup to make sense to someone who hasn't seen the original
                  article. In particular, don't quote signatures (the stuff at the
                  bottom introduced by the "-- " delimiter) unless you're actually
                  commenting on them.

                  You mention a "getFunc.ob j" file, but all the object files mentioned
                  in your Makefile have a ".o" suffix, not ".obj".

                  You talk about C++, but the source you've shown us is C (yes, C and
                  C++ are two different languages), and you're invoking gcc in a way
                  that causes it to act as a C commpiler.

                  You say that you got "the above" errors when trying to link, but the
                  errors you reported were:

                  simlib.h:6: error: expected init-declarator before "extern"
                  simlib.h:6: error: expected `,' or `;' before "extern"

                  Those are compile-time errors, not linker errors.

                  We can't help with C++, Fortran, or Makefiles. There are other
                  newsgroups for those topics: comp.lang.c++, comp.lang.fortr an, and a
                  newsgroup that deals with programming on whatever system you're using,
                  perhaps comp.unix.progr ammer.

                  If you're still having trouble with C, as the error messages indicate,
                  try narrowing down the problem. Make a copy of your source files and
                  start deleting stuff. Trim it down the point where it's as short as
                  possible while still exhibiting the error. Try manually inserting the
                  contents of an include file, replacing the "#include" directive. It's
                  likely that this will help you detect the error yourself; if not, feel
                  free to post your code an error messages here.

                  --
                  Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                  Nokia
                  "We must do something. This is something. Therefore, we must do this."
                  -- Antony Jay and Jonathan Lynn, "Yes Minister"

                  Comment

                  • CBFalconer

                    #10
                    Re: compile errors. pls help

                    beet wrote:
                    >
                    .... snip ...
                    >
                    The simlib.c and simlib.h and simlibdefs.h themselves were good
                    to compile and get an obj file. Once I tried to link simlib.o to
                    another c++ obj getFunc.obj; I got the above errors. All these
                    c/c++ code was supposed to link some Fortran code, using f90...
                    C++ is NOT C. That is a different language, and mixing output code
                    without special care (only with a C++ compiler) is not generally
                    possible. I don't think you are ready for the reasons, so just
                    don't try to do it.

                    --
                    [mail]: Chuck F (cbfalconer at maineline dot net)
                    [page]: <http://cbfalconer.home .att.net>
                    Try the download section.


                    ** Posted from http://www.teranews.com **

                    Comment

                    Working...