Engineering implementation including C and. Cu

Source: Internet
Author: User
Original article address:[Cuda learning-original] engineering implementation that includes C and. Cu! Author:Black tie again

There is a pure C project in which you want to call the function of the. Cu file. There is a cppintegeration example in the project, but this is called in CPP. the functions in the Cu, and the project is directly referenced by many header files and libraries in the SDK. Therefore, portability is very poor. After a few days of exploration, I finally solved the problem of calling the Cu file in the C Project. Share it with you ~~~

 

Create two files, A. Cu AND a_kernel.cu. A. Cu are called interfaces and functions implemented in a_kernel.cu.

Then, right-click a. cu-> properties-> Custom generation step-> General-> command line, and add the following command:

"Certificate (cuda_bin_path)nvcc.exe"-ccbin "$ (vcinstalldir) bin"-I "$ (nvsdkcuda_root) commoninc"-I "$ (cuda_inc_path)"-I. -- Host-compilation C-g-C-M 32-o "$ (inputname ). OBJ "" $ (inputdir) $ (inputname ). CU".

Note: -- Host-compilation must be added. Otherwise, the system prompts link: Fatal error lnk1561: the entry point must be defined. In addition, you must add the SDK and INC paths to include the header files "cutil. H" in A. cu.

Add include <a_kernel.cu> to the header of A. cu.

Note: The generated. OBJ path must be "$ (inputname). OBJ". Otherwise, the system will prompt that F. OBJ cannot be found during compilation.

 

The function f in A. Cu must be defined as follows:

Extern "C" Void F (){}// This must be defined during definition. Otherwise, the system prompts "cannot parse _ f" when linking.

However, when referencing it in file C, you must declare the following statement:

Extern void F (){};// Note: If "C" is added, an error is returned.

In addition, in the C Project linker-input-add dependencies, add

Cudart. Lib cutil32.lib// These two libraries must be added; otherwise, the system prompts: external symbols that cannot be parsed_ Cudaconfigurecall @ 32Errors.

In this way, you can call f () in the C file.

The problem has been solved. You can proceed to the next step !!!

PS: I found that many people use blogs to record technical problems. It is a good habit. Good memory is not as good as that of blog...

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.