CUDA compiler doesn't compile C files in same project

I have main.cu file that includes test.h which is header for test.c and all three files are in same project.

test.h code:

typedef struct { int a; } struct_a; void a(struct_a a);

test.c code:

void a(struct_a a) { printf("%d", a.a); }

main.cu code:

struct_a b; b.a=2; a(b);

Output when building the project:

"nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "CUDA\v7.0\include" -I "CUDA\v7.0\include" -G --keep-dir Debug -maxrregcount=0 --machine 32 --compile -cudart static -g -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o Debug\main.cu.obj "CudaTest\CudaTest\main.cu" 1> main.cu 1> test.c

Errors from building:

Error 1 error LNK2019: unresolved external symbol "void __cdecl a(struct struct_a)" ([email protected]@[email protected]@@Z) referenced in function _main

If i include test.c instead of test.h in main.cu it works. I tried to separately compile test.c, i guess CUDA compiler doesn't include/compile/link(?) test.c file?

-------------Problems Reply------------

As talonmies mentioned, CUDA uses C++ linkage. You need to add extern "C" qualifier to function declaration in test.h:

#ifdef __cplusplus
extern "C"
#endif
void a(struct_a a);

See In C++ source, what is the effect of extern "C"? for explanation.

Category:c# Views:1 Time:2016-04-27

Related post

  • how to display youtube video and mp4 file in same project using webview iphone? 2011-05-16

    how to display youtube video and mp4 file in same project using uiwebview iphone? --------------Solutions------------- Perhaps these will help: http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html http://learningtheworld.eu/20

  • How to submit Two binary(iPhone and iPad) files for same project in App Store? 2012-04-25

    I have created Map application for iPhone and I developed same Map application on iPad too by my client requirement. Now I have same Map app project but two .ipa files one for iPhone and another for iPad. I have already put iPhone version on iTune an

  • compiling C++ and ObjC files in same Project 2011-12-22

    I don't know if this is some silly mistake from my end, or Xcode 4.2.1 is doing something, but I'm unable to compile even a simple project that has both C++ and ObjC files. I've done this in past, but somehow the compiler is treating the C++ header f

  • Building both war and ear files for same project using maven 2011-05-11

    In my project i have both web related stuff(jsps, controllers, ..) and EJB beans. Now i need to build war file with web related stuff and deploy that into tomcat and need to build ear file for EJB's and deploy that into jboss using maven. Can anyone

  • Two .c files have identical compilation settings - VC++ reports no error and doesn't compile one of them 2010-02-24

    I'm trying to compile a set of .c files from an open source project into a static library. I've created a VC++9 project file, set everything up as usual. I add two .c files into the project. They don't have any special compilation settings - all the

  • compiler doesn't recognize the dataset (I added using the wizard or the .xsd files) 2011-08-08

    I created a DataSet object and DataLayer.cs class in root directory. In the DataLayer class I am using System.Data. But the compiler does not recognize my DataSet. The error asks me if I am missing a directive or an assembly reference. I dont think I

  • Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile 2010-08-25

    I have a project in c++ that I would like to view the preprocessor output to see what some #defines and macros would look like. I tried the /p switch to turn on the preprocess to a file option to the compiler (it turns off full compilation and only r

  • Missing Import statements. (VS2008 doesn't compile my project anymore) 2008-11-05

    This is probably a no brainer but... I've just opened a solution in VS2008 and for some reason the compiler doesn't recognised previously compiled errors. I hit build and I get 100s of errors : Name 'IIf' is not declared. Name 'IsNumeric' is not decl

  • Property is in intellisense, but still doesn't compile 2009-10-26

    I renamed one field in the database and added another. Then I removed the table from the DBML file, and re-added it. The I went to access the renamed property. The field shows up in intellisense, but will not compile, throwing a "no definition" error

  • Aspx page doesn't compile when page is copied from another project 2010-02-22

    I often have an issue with compile errors when I copy over an aspx page and code behind file from another project, it seems to work when I create another page and the content manually but if I just copy the files it won't. I have checked to make sure

  • Dynamically compiling and running shaders from file in XNA 2010-09-02

    im wondering if its possible to dynamically compile a pixel-shader from file and apply it to a mesh. First I'll just start with some background information. I have a system which creates HLSL pixel-shaders based on a range of data which is not really

  • stack template doesn't compile push func 2010-11-18

    I wrote this something-like-stack data structure: template<class T> class Stos { class Element { public: T n; Element* prev; Element(const T& k = 0): n(k), prev(0) {} }; Element* member; Stos(Stos&); public: Stos(const T&); ~Stos();

  • Compiling a program with multiple files 2011-05-13

    I just started learning C++ with Dev C++ as my IDE. One of the tutorials I'm using has a page in it about compiling a program made up of multiple files. It's simple stuff at this point, I have one file with a function in it, and the other file has al

  • Why maven compilation doesn't work with "pom" packaging type 2011-08-16

    I don't know why my maven build doesn't generate target/classes in current pom setting, the packaging type must be "pom" in my case, please advise what is wrong... Thanks! <?xml version="1.0" encoding="UTF-8" standalone="no"?> <project xmlns

  • Android Project Compiled with Ant doesn't compile, Illegal Character Error 2011-08-26

    I am using ANT to compile an Android app that I have built. It sounds weird and probably doesn't make a difference, but I used the Android SDK to build a new project and then I used .NET to programatically modify a couple files within the project so

  • Eclipse compilation put lots of .class files in the package folders 2012-01-04

    I must have done something very stupid which has caused the following situation. Basically after compilation of code which I had compiled successfully lots of times previously, all of the .class files have all of a sudden been put in the package fold

  • How to test that some code doesn't compile in C++? 2012-01-25

    Possible Duplicate: Unit test compile-time error I'm wondering if its possible to write a kind of unit test which will verify that a given code doesn't compile. For example, I have a template class: #include <boost/static_assert.hpp> #include

  • Visual Studio 2010 issue with a class that doesn't compile 2012-02-14

    I have a Visual Studio 2010 C# webforms solution with various projects in it. There is a certain class in one of them that acts strangely. If I open some code in another project and then use the "go to declaration" command to get to the class in ques

  • G++ NVCC How to compile CUDA code then Link it to a G++ C++ project 2012-02-23

    Good Day I am looking for help getting started with a project involving CUDA. My goal is to have a project that I can compile in the native g++ compiler but uses cuda code. I understand that I have to compile my cuda code in nvcc compiler, but from m

  • boost 1.49 interprocess example code doesn't compile 2012-03-06

    I try to compile code like this (linux ubuntu, boost 1.49): #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/containers/vector.hpp> int main(

  • Visual Web Developer 2010 - no intellisense and compiler doesn't pick up syntax errors 2012-03-22

    I've just installed Visual Web Developer Express 2010, and I'm trying to write & compile some basic VB code (to do with Object Data Sources). However, when I write my class (which is sitting in APP_Code folder), I find that : 1) I dont get any in

  • How to compile/use intellisense on miscellaneous files in MSVC 2012-04-26

    When I open a .cpp file separate of any project in MSVC, the debugging tools are greyed out and intellisense doesn't seem to be parsing the text. Is there a way to make it so when I open an individual .cpp file, I can compile it straight away without

  • Compiling/Executing a C# Source File in Command Prompt 2009-02-16

    How do you compile and execute a .cs file from a command-prompt window? --------------Solutions------------- CSC.exe is the CSharp compiler included in the .NET Framework and can be used to compile from the command prompt. The output can be an execut

  • Configuring conditional compilation symbol in app.config file 2009-03-17

    Can we configure conditional compilation symbol in app.config file? If it is possible then let us know how to do it. --------------Solutions------------- They are done at different times - one at compile time one at run time. If you are compiling cod

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.187 (s). 11 q(s)