CUDA, Static Library, Global Variables

I am using Visual Studio 2010 and CUDA 4.0 Toolkit and SDK. I am trying to port a “C” application, where I will replace some of the slower library routines with calls to CUDA. My problem is that the application has several static libraries that use global variables, which are defined in the main function file. How can I get the CUDA compiler to not mangle the names of the external global variables? Here is some code that shows what I am trying to do. The program compile, links, and runs without the access to the global variable “globalCount” in staticLib.c, but generates the following error when linking with the global variable access. Thanks.

// file main.cu
#include <stdio.h>

#include “cuda.h”
#include “cuda_runtime.h”

int globalCount = 0;

#include “staticLib.h”

int main() {

cudaDeviceProp prop;

// get the number of CUDA enabled devices
int count;
cudaGetDeviceCount(&count);

// iterate through each device printing information about each devices properties
for (int i = 0; i < count; i++) {

	// get properties for device i
    cudaGetDeviceProperties(&prop, i);

	// print different information about the ith device
    printf("   --- Device %d ---\n", i);
    printf("Name:  %s\n", prop.name);
    printf("Compute capability:  %d.%d\n\n", prop.major, prop.minor);
}

staticLibFunct();

printf("globalCount: %d\n", globalCount);

return 0;

}

// file staticLib.c
#include <stdio.h>

extern int globalCount;

void staticLibFunct() {
printf(“Static Library Function\n”);
globalCount++;
}

1>------ Rebuild All started: Project: cudaAndStaticLib, Configuration: Debug Win32 ------
2>------ Rebuild All started: Project: staticLib, Configuration: Debug Win32 ------
2> staticLib.c
1>
1> E:\Research\linkingLibs\cudaAndStaticLib\cudaAndStaticLib>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin” -I"E:\Research\linkingLibs\cudaAndStaticLib\staticLib" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -G0 --keep-dir “Debug” -maxrregcount=0 --machine 32 --compile -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MDd " -o “Debug\main.cu.obj” “E:\Research\linkingLibs\cudaAndStaticLib\cudaAndStaticLib\main.cu” -clean
2> staticLib.vcxproj -> E:\Research\linkingLibs\cudaAndStaticLib\Debug\staticLib.lib
1> Compiling CUDA source file main.cu…
1>
1> E:\Research\linkingLibs\cudaAndStaticLib\cudaAndStaticLib>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -gencode=arch=compute_10,code=“sm_10,compute_10” --use-local-env --cl-version 2010 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin” -I"E:\Research\linkingLibs\cudaAndStaticLib\staticLib” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -G0 --keep-dir “Debug” -maxrregcount=0 --machine 32 --compile -D_NEXUS_DEBUG -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o “Debug\main.cu.obj” “E:\Research\linkingLibs\cudaAndStaticLib\cudaAndStaticLib\main.cu”
1> tmpxft_00000168_00000000-11_main.ii
1>staticLib.lib(staticLib.obj) : error LNK2001: unresolved external symbol _globalCount
1>E:\Research\linkingLibs\cudaAndStaticLib\Debug\cudaAndStaticLib.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========