Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:22:02+00:00 2026-06-07T21:22:02+00:00

I have a .cu-file that contains both host and device code: // device code

  • 0

I have a .cu-file that contains both host and device code:

// device code
__global__ void
myKernel() { ... }

// host code
#include <boost/thread/mutex.hpp>

boost::mutex myMutex;

int main() { ... }

As you see I do an include of boost’s mutex-functionality. When I compile the file I get an error because of the following warning:

warning C4005: 'BOOST_COMPILER': Macro-Redefinition c:\boost\include\boost-1_49_0\boost\config\compiler\visualc.hpp

So I assume that nvcc handles all the preprocessing for both device- and host-code. Am I right and if yes, how can I avoid that and pass also the preprocessing to cl.exe (MSVC 2010, Win7)?

I already tried to put the host-code in a seperate hpp/cpp-file and include this file in the cu-file – same problem. In the host code I define a surface-reference that will be used in the device code. So this is the reason I need an include in the cu-file and the host-code to be known by the device-code respectively.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:22:05+00:00Added an answer on June 7, 2026 at 9:22 pm

    This is a known limitation of nvcc (technically cudafe, I think). nvcc uses file extension to determine whether a given source file should be processed for device code or passed to the CUDA preprocessors and then device compiler. That compilation trajectory can’t correctly parse some of the very complex declarations that boost contains, and the compile fails.

    The solution is to not import boost headers inside a .cu file. Put your host boost code in a .cc file, device code and kernel launches in a separate .cu file and make some thin wrappers to access the kernel calls from the .cc file. You can still pass all the source to nvcc to compile, but separating the boost imports from the device code eliminates the problem of the front end choking on the boost declarations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .cpp source file that contains both C and C++ code. The
In a folder, I have both my .m file that contains the script and
I have a file that contains: foo1 = 1 foo2 = 2 foo3 =
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
I have Text file that contains data separated with a comma , . How
I have a file that contains around thousands of lines. Format of every line
I have a file that I set using PowerShell that contains the version number
I have a text file that contains a list of filenames, minus the extension,
I have a test file that contains tests taking quite a lot of time
I have a PHP file that contains a lot of if and else statements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.