how to use pgi to build c++ code with dll file and lib file

hello new i can use gpi to built data.c code as data.dlldata.lib files but now i have a c++ code named main.cpp using data.dll and data.lib . how can i to build ? can you give me some advice.

and i use same code data.c

int __declspec(dllexport) data;
 void __declspec(dllexport)
func2(int i)
{
printf("func2: data == %d\n", data);
printf("func2: i == %d\n", i);
data = i;
}

and use pgi to build data.dll and data.lib
also i use vs2010 to build another data1.dll and data1.lib
finally , i use vs2010 to build hello_world.cpp that used data.dll and data1.dll seperately. and when i use data1.dll and data1.lib , my program can run . but i got error when i use data.dll and data.lib as (External symbol __imp__data error LNK2001: could not be resolved
1>D:\goujl\hello_wolrd\Debug\hello_wolrd.exe: fatal error LNK1120: 2 unresolved external command).

and hello_world.cpp is

#include<iostream>
using namespace std;
//extern int add(int,int);
//extern int sub(int,int);

//#pragma comment(lib,"temp01.lib")
extern "C" int __declspec(dllimport) data;
extern "C" void __declspec(dllimport)func2(int);

int main(int argc, char*argv[])

{

//int result1 = add(2,5);

//int result2 = sub(6,3);

//cout<<result1<<"      "<<result2;
data=11;
func2(12);
return 0;

}

Hi,

Could you provide details on the command lines you are using to compile your example here? This would help us better understand the issue.

Thanks in advance.

Best regards,

+chris

thanks for your message. my first situation like this : i hava a file named data.c and main.cpp . so i use PGI to build data.c to data.dll and data.lib :

$ pgcc -Bdynamic -c data.c
           $ pgcc -Mmakedll data.obj -o data.dll 
 //now the d[b]ata.dll and data.lib[/b] have been found
          //and i use PGI to build main.cpp like this 
           $ pgcpp -Bstatic main.cpp data.lib 
////////////program run ok, ///////////

and sencond situation is i use microsoft vs2010 to build data.c ,and i got data1.dll and data1.lib. and use data1.dll and data1.lib to run main.cpp on microsoft vs2010 ,test ok .

and the third situation is : i copy data.dll and data.lib(build by PGI) to vs2010 project to build main.cpp , got erro :

(External symbol __imp__data error LNK2001: could not be resolved
1>D:\goujl\hello_wolrd\Debug\hello_wolrd.exe: fatal error LNK1120: 2 unresolved external command).

and my fouth situation is : i copy data1.dll and data1.lib to my PGI folder to build main.cpp using PGI,

$ pgcpp -Bstatic main.cpp data1.lib

and i got error like :

error LNK2019: unresolved external symbol __imp_data referenced in function main .

i confused, is the dll and lib build by PGI cannot be used by vs2010 ?

Thanks in advance.

Best regards

longzhixi123

Hi,

I checked with our C++ developer on this - objects created by PGI C++ are not interoperable with VS 2010 C++ at this time.

Best regards,

+chris

hi , now i know the problem , will you have the plan to fix this problem . if hava, when ?

thanks a lot

Hi longzhixi123,

In general, objects created by various C++ compilers are not compatible. Things such as name mangling, exception handling, and STL libraries are not standardized and implementation specific.

On Linux, the GNU folks are more open as to how they do name mangling and exception handle as well as the use of their STL so we are able to create object compatibility with g++. Unfortunately the same is not true on Windows. So at least in the foreseeable future, C++ objects will remain incompatible.

Note that we are object compatible for C, so you may be able to write a C interface to your C++ libraries.

  • Mat