cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

use C-SDK in C++ Project

SOLVED
Highlighted
Participant

use C-SDK in C++ Project

Hi.

 

I get a thingworx c-sdk and I want to use it My C++ project.

 

But in thingworx c-sdk, it uses 'namespace' as some parameter's name.

 

As I know 'namespace' is reserved word in C++.

 

How can I resolve it?

Tags (4)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: use C-SDK in C++ Project

Hello,

 

You can't use language reserved keywords as you mentioned correctly.

However, there is a workaround for this using preprocessor macros, but due to compiler variety and complexity I can only offer limited support on this.

 

You'd have to do the following steps:

 

1. Ensure C linkage for all C SDK included headers:

extern "C" 
{
#include "targetheader.h"
}

2. For cases in which variable names include C++ keywords redefine them within the C linkage scope. (it's still including the header in global scope as expected)

extern "C"
{
// redefine namespace to another identifier for C linkage. Used namespace_ignore as a sample
#define namespace namespace_ignore
// include your headers here
#include "targetheader.h"
// remove redefinition of namespace to continue in C++
#undef namespace
}

Using this method you should be able to properly compile your project, the C SDK is not using a keyword as a identifier for a type, which makes this workaround viable. You're also still able to use the namespace keyword in your C++ code.

 

Let me know if you have any questions.

 

Regards,

Pascal

2 REPLIES 2

Re: use C-SDK in C++ Project

Hello,

 

You can't use language reserved keywords as you mentioned correctly.

However, there is a workaround for this using preprocessor macros, but due to compiler variety and complexity I can only offer limited support on this.

 

You'd have to do the following steps:

 

1. Ensure C linkage for all C SDK included headers:

extern "C" 
{
#include "targetheader.h"
}

2. For cases in which variable names include C++ keywords redefine them within the C linkage scope. (it's still including the header in global scope as expected)

extern "C"
{
// redefine namespace to another identifier for C linkage. Used namespace_ignore as a sample
#define namespace namespace_ignore
// include your headers here
#include "targetheader.h"
// remove redefinition of namespace to continue in C++
#undef namespace
}

Using this method you should be able to properly compile your project, the C SDK is not using a keyword as a identifier for a type, which makes this workaround viable. You're also still able to use the namespace keyword in your C++ code.

 

Let me know if you have any questions.

 

Regards,

Pascal

Re: use C-SDK in C++ Project

Thank you!

 

Actually I tried it a days ago... at that time, it was not solution.

 

but this time, it works!

 

Thank you for your help!