Thread: error C2059 with extern "C"

  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654

    error C2059 with extern "C"

    I don't think I've encountered this problem before and it confuses me.
    I just tried to add SQLite to the project, and I get error.
    (Btw, the SQLite source is horrible. Littered with ~450 warnings compiled as C. HORRIBLE!)
    In the header, we have this:

    Code:
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    To make the C code callable from C++ code. Unfortunately, I get the compile error
    error C2059: syntax error : 'string'
    Whenever the header is included from C++ code, not C code.
    extern "C" is invalid in C, so much I know, but it's included from C++ code. The actual SQLite.c file compiles fine.

    Any ideas?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Just tried out "sqlite-amalgamation-3_5_6.zip" and it worked fine for me. Is the error in sqlite3.h? In mine, "string" only ever appears in comments.

    gg

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, sqlite3.h. Here's a sample of the compiler output:
    3>Help.cpp
    3>g:\w00t\visual studio 2005\projects\sqlite\sqlite3.h(43) : error C2059: syntax error : 'string'
    And the error points to
    extern "C"

    It works fine in a new project. Does that mean there might be some define that's getting in the way...?
    Last edited by Elysia; 03-16-2008 at 01:38 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    (Btw, the SQLite source is horrible. Littered with ~450 warnings compiled as C. HORRIBLE!)
    Are you insane? SQLite has probably the best source code out of any open source project I've seen. It is completely readable and well documented. I would love to compare one of your projects of comparable size to SQLite and see who's is more "horrible".

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't doubt the quality of the written code, but it is horrible in sense that they didn't even bother to silence the warnings.
    Ah, now I see the error. Of course. It's located inside a header that is included as part of a template class, hence the error.
    Last edited by Elysia; 03-16-2008 at 01:44 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    That's because it was made to work with many different compilers on many different platforms. It's not as simple as you think.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't know. They didn't even try to cast return types from void to char, for example.
    But anyway, as long as it works, I'm fine with that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I don't doubt the quality of the written code, but it is horrible in sense that they didn't even bother to silence the warnings.
    D. Richard Hipp is convinced that those warnings are benign. Attempts to convince him otherwise have failed and will fail unless you have solid proof that they need to be fixed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extern "C" problem
    By CodeBugs in forum C++ Programming
    Replies: 11
    Last Post: 06-10-2009, 09:14 AM
  2. extern "C"
    By George2 in forum C++ Programming
    Replies: 19
    Last Post: 02-08-2008, 02:33 AM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Unsure of how to properly use extern "C"
    By INFERNO2K in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 11:54 AM
  5. extern "C"
    By viaxd in forum C Programming
    Replies: 6
    Last Post: 12-19-2004, 09:46 AM