Using C++ inside an iOS CocoaPod - c++

I am building a private cocoapod for iOS, and am running into issues with some C++ code. The project builds fine in XCode, but when I attempt to run pod lib lint MyProjectName.podspec I get the following error:
- ERROR | xcodebuild: /path/to/aheader.h:2:10: error: 'string' file not found
The header has the following first line:
#include <string>
Searching for possible solutions, I added the following to podspec (based on CocoaPods: Linking with C++ symbols defined in libPods.a)
s.source_files = "MyProjectName/**/*.{swift,c,m,h,mm,cpp,plist}"
s.library = 'c++'
s.xcconfig = {
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
'CLANG_CXX_LIBRARY' => 'libc++'
}
But it made no difference to the error. Another suggestion I saw was to "use a wrapper", but this piece of code (which is 3rd-party IP that I can not port to Objective C) is already using a wrapper.
How can I build the pod successfully by mixing both Objective C and C++ along with Swift? Any (non-null) pointers would be appreciated.

I had to simply renamed the C++ header extension to .hpp, so it was not included by default in the source_files filter. This resolved the issue, as the wrapper was including the header. Posting this in case someone else runs into the same issue.
Update: Nope, it just lets the app build, but using the pod still doesn't work.

Try explicitly adding stdc++ in the linker options.
s.pod_target_xcconfig = {
'OTHER_LDFLAGS' => '-l"stdc++"'
}

Related

xcode fails to build C++ with Unknown type namespace

I have created a C++ project in Xcode 8.2.1 with a Bridging Header file.
I have added a Point3.hpp and Point3.cpp file into a shared folder.
The types for the cpp and cpp files (in the identity and type inspector) are Default - C++ Source and Default - C++ Header respectively.
The LLVM 8.0 Language settings are:
C++11 [-std=c++11]
libc++ (LLVM C++ standard library with with C++11 support)
When I try to build the project, I find that I get the following error:
I have tried searching to find information to resolve this issue, but most seem to be related to compiling source that is a combination of objective-C and C++ whereas this project was setup as a Swift3 project with C++ bridge. Source code
ex3-Bridging-Header.h
#import "../../../Shared/ex3/math/Point3.cpp"
Point3.cpp
#include "Point3.hpp"
using namespace EX3;
Point3::Point3()
{
} ...
Point3.hpp
#ifndef EX3_POINT3_HPP
#define EX3_POINT3_HPP
namespace EX3
{
class Point3
{
public:
Point3(); ...
compiler settings
After continuing looking, I finally managed to find a working solution. There may be other ways to achieve this but I fixed it by routing the C++ through an Objective C layer. Whilst this seems a little bit clumsy (as it adds an extra bridge layer), as of Swift3, it is reported that there is no direct interop layer to C++.

Eclipse paho mqtt C++ as dependency in another project

I have not much clue how c and c++ works at compile and runtime!
We are trying to use Eclipse Paho C++ library as a dependency in the project and messed up right now.
We have reffered to https://github.com/eclipse/paho.mqtt.cpp/tree/master/src/samples and used the same code in our project but we get this error.
error: 'mqtt' has not been declared class callback : public virtual mqtt::callback
We also have the following in place
Copied all the C and C++ libs(libmqttpp.so libpaho-mqtt3a.so.1.0 libpaho-mqtt3c.so.1 libmqttpp.so.0 libpaho-mqtt3as.so libpaho-mqtt3c.so.1.0 libmqttpp.so.0.1 libpaho-mqtt3as.so.1 libpaho-mqtt3cs.solibpaho-mqtt3a.so libpaho-mqtt3as.so.1.0 libpaho-mqtt3cs.so.1
libpaho-mqtt3a.so.1 libpaho-mqtt3c.so libpaho-mqtt3cs.so.1.0) to /usr/local/lib
Copied .h files(MQTTAsync.h MQTTClient.h MQTTClientPersistence.h) to /usr/local/include
Apart from above 2 steps, do I need to add anything to my project to resolve the problem or I am missing anything.
Finally, It worked after doing the following steps
Download 'C' zip from http://build.eclipse.org/technology/paho/
Copy lib files to /usr/lib/
Modified SConscript(alljoyn/gateway/gwagent/GatewatConnector/samples/) to extend LIBS - gwcnc_env.Prepend(LIBS = ['paho-mqtt3a', 'paho-mqtt3c', 'alljoyn_about', 'alljoyn_services_common', 'alljoyn_notification', 'alljoyn_config', 'alljoyn_gwconnector'])

Xcode noob: Don't understand compiler error message

I'm fairly new to Xcode and have recently gotten an error message that is probably clear to anyone who knows what they're doing, but I am unsure how to react to this one.
I have a project that is mostly C++, with just a few C files in it. Everything was fine until I tried to add some code to find the computer's MAC address. Apple provides a project example (GetPrimaryMACAddress), and I downloaded, built, and tested that. It works just fine.
After that, I simply copied the C source from the Apple example project and included it into my code project. Then I started getting this error message:
I have tried including the IOKit framework explicitly via the linker; no help. I tried adding more #include statement to the Apple example code; no help. I think that I do not understand what the compiler message is telling me regarding importing from module 'Darwin.MacTypes'.
Clicking on the error message took me to a line in usr/include/MacTypes.h:
I'm not clear on how to Import Darwin.MacTypes. I don't really understand how the source code for GetMACAddress could compile so effortlessly in one project and not another. I didn't rearrange nor add nor delete any of the #include statements in the Apple-supplied C file.
I'll bet there is a simple answer that I am just not seeing. How should I react to this error message?
I had a similar problem with types like UInt16 and UInt32. I just included the MacTypes with the following include statement:
#include <MacTypes.h>
This solved all my type-problems for my example c-file.
Let me guess, when you want to compile C++ source, you should create a C++ source file
(On the toolbar: File > New > File.. > Source > C++ File)

Eclipse CDT c++ project using C headers and doing cross compile

we have an application which is written in c++ and now we are trying to use the same application on the ARM board for which we were provided a toolchain.
So when i do a test c++ project it compiles ok and code on the target is executed perfectly.
As we want to use also some of the functionality of the target (eg display,...), that part is for C, headers are C, libraries are C.
So when i tried including C headers i got a lot conversion errors (eg. Description invalid conversion from unsigned int' tostlv_type' locaion: tlv_tags.h C/C++ Problem)
For example function generating problems:
static inline
enum stlv_type _stlv_get_tag_type(unsigned int tag)
{
return STLV_GET_TYPE(tag);
}
When creating C project this all works without a problem, but c++ project hundreds of conversion errors.
So i tried to include this headers in extern "C" block without any success, still same problems.
So can somebody help me combine this :) as there is no possiblity to get c++ from the manufacturer and also changing headers is not an option as new platform releases can come at any time.
Thanks in advance!

Debugging SFML Project in Xcode - Install to Blame?

I followed the instructions to set up SFML here. When I check my /Library/Frameworks folder, all the SFML stuff seems to be there. However, when I check out a project my group is working on using SFML, and when I build, I get a ton of errors. These errors do not exist for my other group members. I think (some of) my errors are caused by SFML not recognizing sf::Input as a type.
Here is my code for one of the header classes in my project:
#pragma once
#include "Mover.h"
class InputMover : public Mover
{
public:
InputMover(const sf::Input* pInput);
//error here - expected unqualified-id before * token
protected:
const sf::Input* m_pInput;
//error here - ISO C++ forbids declaration of Input with no type
};
The parts without errors have been taken out. What do you think the problem is?
EDIT, SOLVED:
The problem was that I installed SFML with makefiles before I just did a copy-install. Some files were conflicting. I tracked down the installed files and deleted them. This seemed to fix the problem.
To use the SFML classes you need to include their definitions.
Add #include <SFML/Window/Input.hpp> to the top of your file.
Also note that to use SFML you must also link to the CoreFoundation, Cocoa and OpenGL frameworks, as well as to libfreetype.