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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

use C-SDK in C++ Project

Mintogo1
5-Regular Member

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?

ACCEPTED SOLUTION

Accepted Solutions
pgrodowski
14-Alexandrite
(To:Mintogo1)

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

View solution in original post

2 REPLIES 2
pgrodowski
14-Alexandrite
(To:Mintogo1)

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

Mintogo1
5-Regular Member
(To:pgrodowski)

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!

Announcements


Top Tags