header file trouble when compiling in Kdevelop

This is a discussion on header file trouble when compiling in Kdevelop within the C Programming forums, part of the General Programming Boards category; So I'm not sure where to start exactly, but here are the main points: using Kubuntu 12.04 - used 'make' ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    8

    header file trouble when compiling in Kdevelop

    So I'm not sure where to start exactly, but here are the main points:
    using Kubuntu 12.04

    - used 'make' and stuff on a project using the Konsole and it compiled and ran fine (this project used some third party libraries and headers), I believe using gcc 4.6

    - tried to include the headers and libs in a Kdevelop project, but when I attempt to build the project, it gives me a long list of errors in one of the headers that look like:

    error: unexpected initializer before 'token' .

    these errors are contained in an extern "C" block, which I understand tell the compiler to compile the code inside the block with a C compiler opposed to a C++ one, and this block has the correct syntax format for this, as follows:

    Code:
    #if defined __cpluscplus
    extern "C" {
    
    //list of function defs
    
    #if defined __cplusplus
    };
    #endif
    
    According to what I found on various forums about this, there shouldn't be a semicolon at the last brace there, but it doesn't solve the error.

    I'm thinking this could be a compiler issue; unfortunately I won't have access to this computer until tuesday to check (although I'm not really sure how I would go about checking...). However, I'm sure that the C++ compiler Kdevelop uses should be able to handle the extern block, right?

    Any thoughts? Thanks, and I'm sorry if I left everything out. Also, I may be way off the mark, so please bear with me there too :P

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    The compiler is almost surely the same in both the cases.
    If it compiled fine from the terminal, then you are doing something wrong when importing the project into Kdevelop.

    Describe what exactly you did for that.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,570
    Quote Originally Posted by dsab123 View Post
    these errors are contained in an extern "C" block, which I understand tell the compiler to compile the code inside the block with a C compiler opposed to a C++ one ...
    False, it tells the C++ Compiler to use a (function) naming system compatible with C Compilers.
    In other words, it turns off C++ Name Mangling.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    8
    Quote Originally Posted by manasij7479 View Post
    The compiler is almost surely the same in both the cases.
    If it compiled fine from the terminal, then you are doing something wrong when importing the project into Kdevelop.

    Describe what exactly you did for that.

    When developing the project in Kdevelop, I did the following:
    - created a new terminal project from scratch,
    - included the main header file in one .cpp file
    - attempted to 'build' the project, which is when I got the aforementioned error,

    and that's about it so far. There are still some library files I need to link properly but I don't think that would make a difference at this stage, right?

    Thanks!

  5. #5
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by dsab123 View Post
    When developing the project in Kdevelop, I did the following:
    - created a new terminal project from scratch,
    - included the main header file in one .cpp file
    - attempted to 'build' the project, which is when I got the aforementioned error,
    Since you already have the makefile, it is redundant to do it your way.
    Just use the importer, from the menu.
    "Project -> Open/Import Project"
    Then select the Makefile (or supported equivalent), and you're done.

    Check if it works, by clicking on build. (If it doesn't, you'll probably need to modify the makefile to add a 'default' or 'all' target.)
    Now create a run configuration, pointing to the executable.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #6
    Registered User
    Join Date
    May 2012
    Posts
    8
    Yep, that worked pretty perfectly. Thanks manasij7479!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header File Trouble... Again
    By jake123 in forum C Programming
    Replies: 11
    Last Post: 03-10-2008, 03:01 PM
  2. Header File Trouble
    By jake123 in forum C Programming
    Replies: 12
    Last Post: 03-07-2008, 04:10 PM
  3. compiling source files and header file at once?
    By 1jackjack in forum C Programming
    Replies: 10
    Last Post: 05-04-2007, 11:06 AM
  4. header file trouble - PLEASE HELP!!!
    By thewinout in forum C++ Programming
    Replies: 0
    Last Post: 03-23-2003, 12:01 AM
  5. Having trouble with header file
    By sbrown72 in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2001, 04:52 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21