can I call an app in OpenFrameworks something other than testApp? - c++

I am working with OpenFrameworks for the first time (I am also rusty at C++).
I am trying to build an app with OFX, and I want to call my app something other than testApp. I am building off the openCVExample code, and I've replaced testApp everywhere with the new name and moved the files from testApp.{h,cpp} to newname.{h,cpp}.
However, when I try to build (using Microsoft Visual C++ 2010 Express, if that makes a difference) I see that the testApp.cpp file is being generated with the contents of newname.cpp and put into my src/ folder. I'm also getting griped at by the build saying that testApp isn't a valid namespace on all lines in newname.cpp where I am trying to call or define member functions (I am using newname::functionName).
I've looked at the build commandline, and it doesn't seem to be looking for testApp.cpp; I've also looked through the linker and other stuff, but don't see it mentioned anywhere in there. Is this some bizarre feature of OpenFrameworks?

In the openframeworks directory there is a project creator app that will do this for you.
D:\workspace\of_v0073_vs2010_release\projectGenerator\projectGenerator.exe
It will also setup addons you've downloaded.
Note:: It creates solutions for VS 2010, i assume this can be opened by Express?

You'll need to change the instances of "testApp" to "newname" in a handful of places:
In testApp.h you'll need to change your app's class name. This is probably the 5th line, which looks like class testApp : public ofBaseApp
In testApp.cpp, you'll need to change all of the function definitions to use the "newname" namespace. These are all of the lines which look like void testApp::setup()
In main.cpp, you'll need to change the argument in ofRunApp() from new testApp() to new newname()
You actually don't have to change the names of the files from testApp.{h,cpp}, though it's still a good idea from an organization standpoint.

Related

Xcode create bundle with cpp files

I'm trying to create a bundle application using Xcode 10.3.
The main code is going to live inside a C++ file, which I added to the bundle project, and I also need to use some Cocoa related stuff.
and here is the catch, anytime I include
#include <Cocoa/Cocoa.h>
I immediately get like 20 errors
which are rather strange. Is there anything else to be added or set in Xcode so I can include Cocoa headers inside a CPP file?
Looks like the solution was easier than expected, you just have to change the compilation type for the cpp file from C++ Source to Objective-C++ Source and then everything compiles as needed.

How to use test framework in my situation?

We have a solution with projects that is generate by cmake.
There is src folder that has all the source code. Proj_Service1, Proj_Service2 and Proj_Service3 reference same Main.cpp and Base_Service.cpp files. In addition, each project has reference to its own ServiceX.cpp file. All projects are console projects (exe). See solution structure below:
-Solution
----Proj_Service1
-------Main.cpp
-------Base_Service.cpp
-------Service1.cpp
----Proj_Service2
-------Main.cpp
-------Base_Service.cpp
-------Service2.cpp
----Proj_Service3
-------Main.cpp
-------Base_Service.cpp
-------Service3.cpp
The reason the structure above in that way is becuase it was decided in the company that each project should include only files that relevant to the project.
I want to add Test_Proj project that will test one of the services or/and all of them using googletest.
When I try to instantiate ServiceX.cpp in Test_Proj, I obviously get linker errors since Proj_ServiceX is not lib and therefore I cannot link to it.
What I thought to do is to create an additional project of type "lib", move Service1.cpp, Service2.cpp and Service3.cpp files to it and make all projects reference it. Basically:
-Solution
----Service_Proj
-------Base_Service.cpp
-------Service1.cpp
-------Service2.cpp
-------Service3.cpp
----Proj_Service1
-------[Reference to Service_Proj]
----Proj_Service2
-------[Reference to Service_Proj]
----Proj_Service3
-------[Reference to Service_Proj]
----Test_Proj
-------[Reference to Service_Proj]
Questions:
Is the solution I suggested above is the only way?
If there is a different, better approach, even the one that requires using other tools, I'll be glad to hear.

Using C++ in swift using a Objective-C Wrapper

I want to build a little project that utilizes the QR Encoder. I simply used Cocoapods to install it within my project and included the QREncoder.h file within my bridging-header, which works just fine for a couple of other Objective-C resources. My problem occurs because I am including the QREncoder.h file which the includes the QR_Encode.h file. This file uses a pretty standard C++ class definition class CQR_Encode{...};, but when I'm trying to compile my code now, I get the following error /PATH_GOES_HERE/Pods/QR-Code-Encoder-for-Objective-C/QRCodeEncoderObjectiveCAtGithub/QR_Encode.h:81:1: Unknown type name 'class'; did you mean 'Class'?. Looking for that error on the internet got me the information, that I need a Objective-C wrapper class for that file, but I thing QREncoder{.h,.mm} should do the job. I also changed file type within the attributes inspector to either 'objective-c++ source' or 'c++ header' but that did not change the error. I also tried setting the 'compile sources as'-setting in build settings, but of course this didn't work since it sets the compile type for all files and since there are Objective-C classes, it won't work. Does anyone have an answer to help me out?

Cannot share header files with another project

I wanted to have one project which would contain common header files that could be used by other projects in the same solution (Unfortunately I cannot accomplish this task). In order to accomplish this task here is what I tried
1-Created a new C++ console application called common.
2-From the properties of this project I changed the configuration type to static Library.
3-I added a simple header file commonheader.h to the project having a class person and built it as a result I got
C:\Users\Raj\Documents\Visual Studio 2010\Projects\Ctest\Debug\Common.lib
4-Now in order to use that header file from a different project I created another project
called Test. And in the properties of test I added Common as a reference
5-I then tried to access the person class however the VS2010 still complains that it cannot find the person class.
Any suggestions on what I might be doing wrong ? . I added the path
C:\Users\Raj\Documents\Visual Studio 2010\Projects\Ctest\Debug\ in addition include addition files of the Test project. Any ideas how I can access the person class
AFAIK the .lib files only contains the compiled source of your implementations, you still need to include the header files themselves to get access to the interface

C++ and Objc Build Errors

I have been trying to add MobileSynth to my application for some time now and I am only running into errors.
I have followed the steps here which explain how to add a project into another one.
When I compile, both projects are compiled correctly without errors, but the moment I try import the code into my objective C source code I get a large number of errors.
This is a screenshot of the errors.
Im sure there are more errors than these as there seems to be something wrong with the dependencies.
I also approved Xcodes recommendation to convert the project 2 (containing the objective C viewcontrollers with .mm extensions and the .cpp files) from an old 3.something version to the version 4 project type, and made the snapshot. Didnt seem to change anything.
I am not sure how to solve these issues. I would really appreciate any help.
Use using namespace instead of namespace.
You're aware that files that use C++ need the .mm extension. You also need to consider import dependencies. Since this header contains C++, any other file that imports it will also need to have the .mm extension. I'm almost positive that's what's happening to you.
I generally try to keep C++ quarantined to the implementation files for this very reason.
Also, for clarification on previous advice:
// Correct
namespace synth { class something; }
// Incorrect
using namespace synth { class something; }
// Optional
namespace synth { class something; }
using namespace synth;