Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nkhan8
Beginner
273 Views

No error for declspec(dllexport) in Linux

Hi,

I have below code in Linux which is working fine without any error. Since __declspec(dllexport) and __declspec(dllimport) are windows specific then why compiler is not complaining about it?

code in .hpp is as below.

#ifdef EXPORT_MY_DLL

#define MYEXPORTER __declspec(dllexport)

#else

#define MYEXPORTER __declspec(dllimport)

#endif

MYEXPORTER bool isInitialised();

and code in cpp is as below.

MYEXPORTER bool isInitialised(){

return true;

}

Please help me to understand this as I have mostly worked on windows so keen to understand why there is no warning or error.

Thanks.

 

0 Kudos
4 Replies
Olga_M_Intel
Employee
273 Views

Which compiler version and how (command line) do you use? Have you included the header file?

I easily get the error message

 $ icpc test.cpp
In file included from test.cpp(1):
test.hpp(11): error #1292: unknown attribute "dllimport"
  MYEXPORTER bool isInitialised();
  ^

test.cpp(3): error #1292: unknown attribute "dllimport"
  MYEXPORTER bool isInitialised(){
  ^

compilation aborted for test.cpp (code 2)

nkhan8
Beginner
273 Views

I can see you have got error but I am still not sure why I am not getting this error. I am using CMAKE with the 18 version of intel compiler. yes i have include my header in cpp file.

I have also written a test program to do something like below.

test.hpp

__declspec(dllexport) bool isInitialised();

test.cpp

__declspec(dllexport) bool isInitialised(){

return true;

}

 

The above code also working fine. now I am only getting error i misspell as below.

__declssdfdspec(dllexport) bool isInitialised(){

return true;

}

 

 

nkhan8
Beginner
273 Views

Ok. error is not coming due to the compiler option -wd1292 which has been used in CMAKE. but should I be using it?

Olga_M_Intel
Employee
273 Views

naddy wrote:

Ok. error is not coming due to the compiler option -wd1292 which has been used in CMAKE. but should I be using it?

This is exactly what -wd1292 option does - disables error #1292 :)

So, it is obvious you don't get an error/warning.

Reply