I sent this problem to the PGI technical support email, but never got a notification back.

When compiling a library that exports data, applications linking to the import library cannot see the symbols. Linking with an object file would allow the applications to see the symbol. Here is a small example

[chulbert@fourierwinx64 ~]$ cat file1.c
#include “file1.h”
char *str = “string”;
[chulbert@fourierwinx64 ~]$ cat file1.h
extern char *str;
[chulbert@fourierwinx64 ~]$ cat file2.c
#include <stdlib.h>
#include <stdio.h>
#include “file1.h”

int main(void)
[chulbert@fourierwinx64 ~]$ pgcc -Mmakedll:export_all file1.c
Creating library file1.lib and object file1.exp
[chulbert@fourierwinx64 ~]$ pgcc file2.c file1.lib
file2.obj : error LNK2019: unresolved external symbol _str referenced in function _main
file2.exe : fatal error LNK1120: 1 unresolved externals


-Mmakedll=export_all is not an external flag and we do not expose this flag to user because it could contain a bug(I believe it did have a bug before).

Your will need to specify in your code what you want to export or put it in *.def file. If you use .def file, the name must be the same as a source file name, for example file1.c must have file1.def.

From your code:

I would remove the include file1.h from file2.c if you are going to import it. Because you are having duplicate variable one that is included and the other is imported.

Here is some changes:


#include “file1.h”
char __declspec(dllexport) *str = “string”;


extern char * str;


#include <stdlib.h>
#include <stdio.h>

char __declspec(dllimport) *str;

int main(void) {

pgcc -Mmakedll file1.c -o libme.dll
pgcc -Mdll file2.c libme.lib


I realize it’s an “unsupported” flag, but it is a very convenient flag to have. Regardless, I think the issue could be fixed to improve the flag. The code I posted was a very simple example. Realistically, the code this occurs in is not mine so I would rather not maintain the source code. In the case of the Qhull library which is what I was compiling, I just added extra exports for the few symbols that this occurred with.