C - DLL Export
-
I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant
-
I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant
Hi, I've never seen
extern "C"
without curly brackets, so tryextern "C" { ... unmangled C code here ...}
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant
-
Hi, I've never seen
extern "C"
without curly brackets, so tryextern "C" { ... unmangled C code here ...}
:)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
extern "C"
will work without curly brackets. Curly brackets are required if you need to include multiple lines in the scope ofextern "C"
.«_Superman_»
I love work. It gives me something to do between weekends. -
I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant
Check the line number where the error occurs and post the code. The code that you've posted here has the correct syntax.
«_Superman_»
I love work. It gives me something to do between weekends. -
extern "C"
will work without curly brackets. Curly brackets are required if you need to include multiple lines in the scope ofextern "C"
.«_Superman_»
I love work. It gives me something to do between weekends.If we're being picky here, the actual condition is not "multiple lines" but "more than a single declaration". Refer section 7.4 of the standard. For example,
extern "C"
double
sqrt(
double)
;is OK, but
extern "C" double sqrt(double); double exp(double);
and
extern "C" int square(int x) {return x*x;}
are not.
Software rusts. Simon Stephenson, ca 1994.
-
What compiler do you use in your IDE environment? I think
__declspec(dllexport)
is only for MS compiler, not for gcc.I use GCC compiler.
-
Check the line number where the error occurs and post the code. The code that you've posted here has the correct syntax.
«_Superman_»
I love work. It gives me something to do between weekends.line 2
-
I use GCC compiler.
If you're using
gcc file.c
from the command line, then that could be the problem - gcc is the C compiler andextern "C"
is C++ code. Useg++ file.c
, or make sure the file extension is .cpp or .c++ for gcc to compile it as C++. -
I use CodeBlocks 10.05, I want use C dll in .NET. I write following code in CodeBlocks 10.05 compiler, but get error when I build it. #include <stdio.h> extern "C" __declspec(dllexport) int GetLuckyNumber() { return 13; } ERROR MESSAGE error: expected identifier or '(' before string constant
-
If you're using
gcc file.c
from the command line, then that could be the problem - gcc is the C compiler andextern "C"
is C++ code. Useg++ file.c
, or make sure the file extension is .cpp or .c++ for gcc to compile it as C++.