Linking Problems (Unresolved symbols)

i have build a a1.c file in windows with PGI 17.3
this is code

extern __declspec(dllexport) void __cdecl Convolution2D(unsigned char * restrict data , unsigned char * restrict outdata , int width, int height ,unsigned char * restrict filter, int fwidth, int fheight)
{
	int imagecount = width*height;
	int filtercount = fwidth*fheight;

	if (fwidth % 2 == 0)
		fwidth = fwidth + 1;
	if (fheight % 2 == 0)
		fheight = fheight + 1;
	
	
	int halfwidth = fwidth / 2;
	int halfheight = fheight / 2;
	//heith = row
	//width = col

	int allheight = height - fheight;
	int allwidth = width - fwidth;

	int endheight = height - halfheight;
	int endwidth = width = halfwidth;

	int filterall = 0;
	for (int i = 0; i < filtercount; i++)
	{
		filterall += filter[i];
	}

#pragma acc data  copyin(data[0:imagecount],filter[0:filtercount]),copyout(outdata[0:imagecount])
	{
#pragma acc parallel loop present(outdata,data,filter)
		for (int i = 0; i < allheight; i++)
		{
#pragma acc loop 
			for (int j = 0; j < allwidth; j++)
			{
				int findex = 0;
				double dataall = 0;
				for (int m = 0; m < fheight; m++)
				{
					int index = (i + m)*width + j;
					for (int n = 0; n < fwidth; n++)
					{
						dataall = dataall + data[index] * filter[findex];
						findex++;
						index++;
					}
				}
				outdata[(i + halfheight)*width + j + halfwidth] = (unsigned char)(dataall / filterall);
			}
		}
	}


}

and build with below command in windows

pgcc -acc a1.c -c -Bdynamic -ta=tesla:cc50
pgcc -acc -Mmakedll -o a1.dll a1.obj -laccapi -laccg -laccg2 -laccn -laccnc -lblas -lcudadevice -lcudafor -lcudafor80 -lcudaforblas -llapack -lnspgc -lpg -lpgc -lpgc14 -lpgmalloc -lpgmp


But i got below error ,and i had try to build without cuda it will be ok.


a1.obj : error LNK2019: unresolved external symbol _pgimain referenced in functi
on main
libpgc.lib(pgstdinit.obj) : error LNK2019: unresolved external symbol _environ r
eferenced in function __io_environ
libpgc.lib(pgstdinit.obj) : error LNK2019: unresolved external symbol __iob_func
 referenced in function __io_stdin
libpgc.lib(pgstdinit.obj) : error LNK2019: unresolved external symbol _filbuf re
ferenced in function __io_fgetc
libpgc.lib(pgstdinit.obj) : error LNK2019: unresolved external symbol _flsbuf re
ferenced in function __io_fputc
libpgmalloc.lib(pgmalloc_win.obj) : error LNK2019: unresolved external symbol __
imp_OpenProcessToken referenced in function SetLockMemoryPrivilege
libpgmalloc.lib(pgmalloc_win.obj) : error LNK2019: unresolved external symbol __
imp_AdjustTokenPrivileges referenced in function SetPrivilege
libpgmalloc.lib(pgmalloc_win.obj) : error LNK2019: unresolved external symbol __
imp_LookupPrivilegeValueA referenced in function SetPrivilege
a1.dll : fatal error LNK1120: 8 unresolved externals







Hi ColinLiang52245,

It looks like you’re adding some of the static libraries to your link. The compiler will automatically added the necessary libraries for you, the exception being the OpenACC runtime which is a known issue (reported as TPR#22971) and will be addressed in a future release.

Also, in order to include OpenACC code within dynamic objects, either DLLs and .so, you need to compile and link without relocatable device code (RDC) support enabled. RDC requires a device linker which is unavailable for dynamic linking. To disable RDC, compile and link with “-ta=tesla:cc50,nordc”.

PGI$ pgcc -acc a1.c -c Mdll -ta=tesla:cc50,nordc
a1.c:
PGI$ pgcc -acc -Mmakedll -Mdll -ta=tesla:cc50,nordc -o a1.dll a1.obj -laccapi -laccg -laccg2 -laccn -laccnc
   Creating library a1.lib and object a1.exp
PGI$

Hope this helps,
Mat



below is my computer build shell , does a1.c build ok in your computer?? Is my system’s problem??
thank you very much for your reply !!


C:\Users\colin>pgcc -acc a1.c -c Mdll -ta=tesla:cc50,nordc
a1.c:

C:\Users\colin>pgcc -acc -Mmakedll -Mdll -ta=tesla:cc50,nordc -o a1.dll a1.obj -
laccapi -laccg -laccg2 -laccn -laccnc
   Creating library a1.lib and object a1.exp
libaccn.lib(cuda_init.obj) : error LNK2019: unresolved external symbol __PGI_CUDA_LOC referenced in function __pgi_uacc_cuda_load_module
libaccn.lib(cuda_init.obj) : error LNK2019: unresolved external symbol __PGI_CUDA_CAP referenced in function __pgi_uacc_cuda_checkdevice
a1.dll : fatal error LNK1120: 2 unresolved externals

The link does work for me but I was using the 16.10 compiler. The error you’re seeing is a new problem in the 17.1 compiler where these two global variables aren’t being properly exported. It’s a known issue (TPR#23906) that is actively being addressed but I don’t have an ETA on when the fix will be available.

The work around is to use the 16.10 compiler which you can download from the archive page found under the download tab at the top of this page.

-Mat

Hi , i can not see your reply?
I am use OpenAcc + Nvidia Gpu in meachine vision , and it must run in windows,

Sorry about that. For some reason the link I added to the response caused the post to be invisible. I edited the response taking out the link, and now it’s visible.