Extern C Syntax Error String
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies error c2059 syntax error string matlab of this site About Us Learn more about Stack Overflow the company Business
Error C2059 Syntax Error 'sizeof'
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Syntax Error String Python
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign
Error C2059 Syntax Error 'constant'
up Error C2059: syntax error : 'string' up vote 2 down vote favorite I have looked at other posts and to be honest I am still not sure what is causing the problem. I am programming in Visual Studio and I have the following code: (this is a C main) int main(int arc, char **argv) { struct map mac_ip; char line[MAX_LINE_LEN]; char extern c example *arp_cache = (char*) calloc(20, sizeof(char)); //yes i know the size is wrong - to be changed char *mac_address = (char*) calloc(17, sizeof(char)); char *ip_address = (char*) calloc(15, sizeof(char)); arp_cache = exec("arp -a", arp_cache); It uses the following cpp code: #include "arp_piping.h" extern "C" char *exec(char* cmd, char* arp_cache, FILE* pipe) { pipe = _popen(cmd, "r"); if (!pipe) return "ERROR"; char buffer[128]; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) { strcat(arp_cache, buffer); } } _pclose(pipe); return arp_cache; } With the matching header file: #ifndef ARP_PIPING_H #define ARP_PIPING_H #endif #ifdef __cplusplus #define EXTERNC extern "C" #else #define EXTERNC #endif #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/17741302/error-c2059-syntax-error-string extern “C” DLL: Debug is OK, Release throws Error C2059 up vote 4 down vote favorite I've got a DLL that I've created as a C++ Win32 application. To prevent name mangling in my DLL, I have used the EXPORT definition defined below: #ifndef EXPORT #define EXPORT extern "C" __declspec(dllexport) #endif EXPORT int _stdcall SteadyFor(double Par[], double Inlet[], double Outlet[]); To get this http://stackoverflow.com/questions/3094573/extern-c-dll-debug-is-ok-release-throws-error-c2059 code to compile, I had to go into the project's Properties and set the C/C++ Calling Convention to __stdcall (/Gz) and set Compile As to Compile as C++ Code (/TP). This worked in Debug mode, but Release mode is throwing error C2059: syntax error: 'string' on all of my EXPORT functions - even though I have configured the Release mode settings to be the same as the Debug settings. How do I get Release Mode to compile? Regards, ~Joe (Developing under Visual Studio 2008 Professional) EDIT: A lot of comments about my #define, which does not appear to be causing any problems. To eliminate the confusion, my header file has been rewritten as follows: #ifndef coilmodel_h #define coilmodel_h extern "C" __declspec(dllexport) int _stdcall steadyFor(double Par[], double Inlet[], double Outlet[], char* FileIn, char* FileOut); #endif That is all of it. The error is: Description error C2059: syntax error: 'string' File coilmodel.h Line 4 Again, this error only appears in Release mode, not Debug mode. Project is a C++ Win32 DLL application. c++ dll extern share|improve this question edited Jun 22 '10 at 15:55 asked Jun 22 '10 at 15:22
Programming Boards C++ Programming error C2059 with extern "C" Getting started with C or C++ | C Tutorial http://cboard.cprogramming.com/cplusplus-programming/100442-error-c2059-extern-c.html | C++ Tutorial | C and C++ FAQ | Get a http://www.pcreview.co.uk/threads/extern-c-returns-error.1223153/ compiler | Fixes for common problems Thread: error C2059 with extern "C" Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 03-16-2008 #1 Elysia View Profile View Forum Posts C++まいる!Cをこわせ! Join Date Oct syntax error 2007 Posts 24,472 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" { syntax error string #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? Originally Posted by Adak 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. Originally Posted by Salem 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. 03-16-2008 #2 Codeplug View Profile View Forum Posts Registered User Join Date Mar 2003 Posts 4,941 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 03-16-2008 #3 Elysia View Profile View Forum Posts C++まいる!Cをこわ
.NET platform and i try to use [extern "C"] infront of the function decleration to get a clean function name in the DLL. this is my simple code: 1 class CTestDllApp : public CWinApp 2 { 3 public: 4 CTestDllApp(); 5 extern "C" __declspec(dllexport) int MyFunction(int); 6 // Overrides 7 public: 8 virtual BOOL InitInstance(); 9 DECLARE_MESSAGE_MAP() 10 }; at line 5 i get error for the 'string' decleration (g:\TestDll\TestDll\TestDll.h(21): error C2059: syntax error : 'string') What is the problem??? thanks Lio Lio, Aug 5, 2003 #1 Advertisements Richard Grimes [MVP] Guest Lio wrote: > Hi > > I am using the MFC DLL project in .NET platform and i try to use > [extern "C"] infront of the function decleration to get a clean > function name in the DLL. > this is my simple code: > > 1 class CTestDllApp : public CWinApp > 2 { > 3 public: > 4 CTestDllApp(); > 5 extern "C" __declspec(dllexport) int MyFunction(int); > 6 // Overrides > 7 public: > 8 virtual BOOL InitInstance(); > 9 DECLARE_MESSAGE_MAP() > 10 }; > > at line 5 i get error for the 'string' decleration > (g:\TestDll\TestDll\TestDll.h(21): error C2059: syntax error : > 'string') > > What is the problem??? Umm, you have a C++ class and then you say that one of its methods has a C name - doesn't that seem odd to you? The C++ mangled name (sorry 'decorated' name) has information in it about the class, the parameters and return value which is used by the C++ compiler when trying to write code that calls the class. If you could make the method extern "C" then this information would not be available to the compiler. You are trying to export the method from the DLL, but this is an ugly way to do it. You can export the mangled name and import that into C# with [DllImport] but you have the problem of the implicit first parameter 'this' pointer. Its far better to write some managed C++ that has a public managed class with a public MyFunction that creates a CTestDllApp unmanaged object and delegates the call to that object's methods. Richard -- my email is encrypted with ROT13 (www.rot13.org) Richard Grimes [MVP], Aug 12, 2003 #2 Advertisements Phil Boyd Guest If you are trying to export a C++ method from your dll as a C function - you'll have to wrap it. The C/C++ Users Journal this month has a good article on how to do this in the Conversations article by Herb Sutter and Jim Hyslop. "Richard Grimes [MVP]"