error C2059 with extern "C"

This is a discussion on error C2059 with extern "C" within the C++ Programming forums, part of the General Programming Boards category; I don't think I've encountered this problem before and it confuses me. I just tried to add SQLite to the ...

  1. #1
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171

    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    (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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,973
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 01:33 AM
  3. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  4. Unsure of how to properly use extern "C"
    By INFERNO2K in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 10:54 AM
  5. extern "C"
    By viaxd in forum C Programming
    Replies: 6
    Last Post: 12-19-2004, 08:46 AM

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