Extern C Error C2059
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 of this site About Us Learn more about Stack Overflow the company Business Learn c2059 syntax error more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Error C2059 Syntax Error String Matlab
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like
Error C2059: Syntax Error : 'type'
you, helping each other. Join them; it only takes a minute: Sign up 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
Error 1 Error C2059 Syntax Error
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 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 error c2059 syntax error 'sizeof' 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 jp2code 12.9k1991175 I think the code you posted is not relevant to the problem. Can you tell us which line chokes as well as post the code for that line. From the code you posted it looks like you do not have EXPORT defined in Release mode. –Romain Hippeau Jun 22 '10 at 15:26 See my "Edit" section above. I wasn't able to explain it all here. –jp2code Jun 22
Windows Desktop Development > Visual C++ Question 0 Sign in to vote Hi All I have following code in my .h file extern "C" { __inline short cosi_atomic_add16(volatile short *p,short n); }here is the syntax error string python code in .asm file _DATA SEGMENT ;cosi_atomic_add16 p QWORD 0 n WORD 0 value c++ syntax error WORD 0 _Data ENDS .CODE cosi_atomic_add16 PROC mov ax,n mov rax,p lock xadd [rax],ax mov value,ax ret cosi_atomic_add16 ENDP END error c2143: syntax error : missing ';' before '{' when i complie the above code i get following errorError 282 error C2059: syntax error : 'string'in .h filePlease help meThanks,rahul Thursday, December 10, 2009 5:20 AM Reply | Quote Answers 3 Sign in to vote extern "C" can http://stackoverflow.com/questions/3094573/extern-c-dll-debug-is-ok-release-throws-error-c2059 only be used with C++, not with C. Try this: #ifdef __cplusplus extern "C" { #endif __inline short cosi_atomic_add16(volatile short *p,short n); #ifdef __cplusplus } #endif - Wayne Marked as answer by Nancy Shao Friday, December 11, 2009 9:14 AM Thursday, December 10, 2009 6:33 AM Reply | Quote All replies 0 Sign in to vote I don't see the word "string" at all in the code that you have posted. Check which https://social.msdn.microsoft.com/Forums/vstudio/en-US/eb89a44d-35cb-4ad0-88ce-cf9664c9fcbc/error-c2059-syntax-error-string?forum=vcgeneral line the error occurs and post the relevant code. If you're using the stl string class, you're probably missing the std namespace. So you could rewrite it as std::string.«_Superman_» Microsoft MVP (Visual C++) Thursday, December 10, 2009 5:29 AM Reply | Quote 0 Sign in to vote Hi Thanks for your reply.Tha error occurs at extern "C" line extern "C" { __inline short cosi_atomic_add16(volatile short *p,short n); }Thanks,rahul Thursday, December 10, 2009 6:09 AM Reply | Quote 0 Sign in to vote I feel, you need to initilize p and n before passing to cosi_atomic_add16.Thanks Mike --------Please mark as answer if it is useful---------- Proposed as answer by viktorovich andrej Tuesday, October 16, 2012 12:08 PM Thursday, December 10, 2009 6:26 AM Reply | Quote 3 Sign in to vote extern "C" can only be used with C++, not with C. Try this: #ifdef __cplusplus extern "C" { #endif __inline short cosi_atomic_add16(volatile short *p,short n); #ifdef __cplusplus } #endif - Wayne Marked as answer by Nancy Shao Friday, December 11, 2009 9:14 AM Thursday, December 10, 2009 6:33 AM Reply | Quote 0 Sign in to vote Thanksnow its working now....:)Regards,rahul Thursday, December 10, 2009 8:11 AM Reply | Quote Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If yo
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. https://msdn.microsoft.com/en-us/library/t8xe60cf.aspx The content you requested has been removed. You’ll be auto redirected in 1 second. http://www.pcreview.co.uk/threads/extern-c-returns-error.1223153/ C/C++ Building Reference C/C++ Build Errors Compiler Errors C2001 through C2099 Compiler Errors C2001 through C2099 Compiler Error C2059 Compiler Error C2059 Compiler Error C2059 Compiler Error C2001 Compiler Error C2002 Compiler Error C2003 Compiler Error C2004 Compiler Error C2005 Compiler Error C2006 Compiler Error C2007 Compiler Error C2008 Compiler Error C2009 Compiler Error C2010 syntax error Compiler Error C2011 Compiler Error C2012 Compiler Error C2013 Compiler Error C2014 Compiler Error C2015 Compiler Error C2017 Compiler Error C2018 Compiler Error C2019 Compiler Error C2020 Compiler Error C2021 Compiler Error C2022 Compiler Error C2026 Compiler Error C2027 Compiler Error C2028 Compiler Error C2030 Compiler Error C2032 Compiler Error C2033 Compiler Error C2034 Compiler Error C2036 Compiler Error C2039 Compiler Error C2040 Compiler Error C2041 Compiler Error C2042 c2059 syntax error Compiler Error C2043 Compiler Error C2044 Compiler Error C2045 Compiler Error C2046 Compiler Error C2047 Compiler Error C2048 Compiler Error C2050 Compiler Error C2051 Compiler Error C2052 Compiler Error C2053 Compiler Error C2054 Compiler Error C2055 Compiler Error C2056 Compiler Error C2057 Compiler Error C2058 Compiler Error C2059 Compiler Error C2060 Compiler Error C2061 Compiler Error C2062 Compiler Error C2063 Compiler Error C2064 Compiler Error C2065 Compiler Error C2066 Compiler Error C2067 Compiler Error C2069 Compiler Error C2070 Compiler Error C2071 Compiler Error C2072 Compiler Error C2073 Compiler Error C2074 Compiler Error C2075 Compiler Error C2077 Compiler Error C2078 Compiler Error C2079 Compiler Error C2081 Compiler Error C2082 Compiler Error C2083 Compiler Error C2084 Compiler Error C2085 Compiler Error C2086 Compiler Error C2087 Compiler Error C2088 Compiler Error C2089 Compiler Error C2090 Compiler Error C2091 Compiler Error C2092 Compiler Error C2093 Compiler Error C2094 Compiler Error C2095 Compiler Error C2097 Compiler Error C2099 TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Compiler Error C2059 Visual Studio 2015 Other Versions Visual Studio 2013 Visual Studio 2012 Visual Studio 2010 Visual Studio 2008 Visual Studio 2005
.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]"