I've been running into this strange problem lately where in my Cocoa app project in Xcode I get the error that the file was not found when using "fopen" (errno 2), called from a C++ file. I made sure to copy these files into the project's directory, then I dragged them from the Finder directory into the Xcode project tree. And finally, in the scheme's options I checked "use custom directory" and entered the directory where I have the project and all the files. The programme builds fine, but during runtime I get a BAD ACCESS error and I can see that my FILE* variable is still NULL. The command that throws the exception is actually "fread" two lines later, but it's only because "fopen" didn't do its job.
This whole setup has worked fine before in pure C++ projects. But this is different because it started as a Cocoa app in Objective-C (because I intended to use C++ for the programme's main logic). At some point I also had to change the extensions of all the ".m" files to ".mm" or the compiler wouldn't even find the C++ standard library! (but this is probably beside the point)
So the question is.. what else do I need to check in order to have the programme find the files I'm trying to open?
NOTE: the backbone of the project is written in C++, and I'm only using Cocoa in order to be able to dram images on the screen, so if anyone has a better approach to including graphics in a C++ project I'm all ears.
Thanks for reading
EDIT: I'm using Xcode 12.4 and Catalina 10.15.7
Cocoa apps do not work with files the same way as command-line C++ apps. Cocoa apps create an app bundle, which is where the files you want to read should be. If you have files you want to read in a Cocoa app, add them to the project. When you add the files to the project, they will get copied to the app bundle. Make sure they are in the app target's Copy Bundle Resources build phase.
Use the methods in the Bundle class to locate the files instead of fopen. The following Swift code locates a file named "MyFile.txt" in the main app bundle:
let mainBundle = Bundle.main
let fileURL = mainBundle.url(forResource: "MyFile", withExtension: "txt")
Related
I am trying to run OpenCV projects in Xcode and it seems like there's a new need to provide an info.plist for C++ applications NSCameraUsageDescription.
2018-09-28 00:03:15.181948+0800 k_nearest_detector_v2[23505:710470] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
Program ended with exit code: 9
How do I go about creating a .plist file for a C++ project as it has never been needed before.
Found a solution. Put the file with the desired NSCameraUsageDescription, NSMicrophoneUsageDescription (or others) with the assembled file from XCode (See screen shots below). For the Release and Debug versions.
You can even automate the steps described by #Valery Gromov. Just copy the file in the Build Phases. Uncheck the Copy only when installing checkbox to be able to run it directly from Xcode.
I am currently writing a super basic plugin using the JUCE framework and C code generated from a the Heavy Pure Data Online Compiler. The source code builds fine, however no standalone application, AudioUnit or VST are created by Xcode. My guess is that the project is not setup properly to use the included code, however I am still learning my way around Xcode and can't seem to work out what the problem is to fix the below errors. Any suggestions on how I can fix this?
Edit: Finally started using git and uploaded the project to GitHub here.
The projucer file you included is missing the heavy source folder. Add them in projucer on the left side in the file explorer area (right click in the file area on source and choose add existing files...
Hint the save and open in ide icon on top of the window
and there you go ... no linker error.
tested with XCode 8.3.3
Two remarks:
Never add files anywhere else than in projucer
You canĀ“t use XCode 9 beta with JUCE
I am trying to learn C++ from some Stanford Course and they have a custom library which contains a bunch of header files(.h) and their associated source (.cpp) files.
I want to create new C++ projects in xcode 6.x to try out code and include those custom header files in my new projects.
I have no freaking idea how to include those files in my project so that i can peacefully #include "blahblahblah.h" and use functions from that header file without issues.
I am new to both xcode, c++(although i know some coding part) and anything else with this process.
Summary:
I have a folder Library which contains a series of .h and .cpp
files.
I have XCode 6.x.x/Eclipse installed.
I want to create a new C++ project and use #include
"OneOfThoseHeaderFiles.h" and then use a function or something from
those header files.
Also assume i have no clue how to run some command line codes that i see a lot of.
If someone can please tell me in the most simple way(preferably step-by-step) i would be so eternally grateful and sing praises to you until the day i die :)
Note: Either XCode or Eclipse is fine. I really just want to start coding.
I have spent the better part of a whole week trying out xcode, eclipse etc and trying to follow a ton of steps to get it working but i just cant get how to add the files without issues. Either the info seems to be for Xcode 4.x and every menu seems changed or the suggestions are so complicated that a novice like me cant figure it out.
First off, almost all the information for Xcode will be available on the Apple Developer's portal:
https://developer.apple.com/library/prerelease/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/start_project.html#//apple_ref/doc/uid/TP40010215-CH2-SW5
To create a simple static library on Xcode 6 you start by creating a new project, then under OS X - Framework and Library select Library, on the next window change the Framework to None (Plain C/C++ Library) and static (since that is what your are stating).
Once your project is created, add the existing headers and sources to your project, either by dragging them with the mouse or with the add files drop menu from the right click functionality, you can create a new group in Xcode if you want some order for them.
When adding the files, on the add window shown you can select to either copy them or use their current location.
If needed you might have to change the "header search path" in your target configuration under "Build Settings", if it is the first time you are using Xcode some of this will sound weird but I am sure you will find most of it on the Apple Developers portal in great detail.
If you want to test the files without having to create an external static library you could create a command line project and test them faster and easier.
I have made my project in C++ and used SFMl 2.1, I also have loaded images from disk and when I'm trying to run its .exe file its giving error in image loading.
For now I'm trying to run its own .exe fie (in Debug or Release folder of project).
i want to make this .exe file for my friends who are not programmers so that my game would run on their PCs as well.
If someone know to make .exe so please help!
First, try to put the images beside the exe file.
After that, your friends probably won't have all the development DLL and libs needed for your app to work. You can use depends.exe to know what is needed for your app to start. Put all those file beside your exe and it should work on most PCs.
Bonus tip
Often, when you experience this kind of problem (application crash when starting directly outside the project), the simplest solution, which is language-agnostic, is to make your app write to a new file within your main function and look where it ends up in your project hierarchy after you ran your app directly (outside the IDE/project).
You'll see right there where the relative root of your app is. Most of the time, it's right next to the compiled file, depending on the language you chose.
I have a basic C++ applicatin build using g++ and -framework ...
when I run it, I get a :
Working in unbundled mode. You should build a .app wrapper for your Mac OS X applications.
(which is not std::couted by any of my application).
What causes this, and how can I get rid of it?
Thanks!
You need to create a folder structure and place the binary in a special location. For an example with explanation see this Qt page
Mac OS X handles most applications as "bundles". A bundle is a directory structure that groups related files together. Bundles are used for GUI applications, frameworks, and installer packages. These are presented to the user as one file in the Finder. When set up correctly, bundles make for easy deployment. All one needs to do is to archive the application using some preferred method. Users then open the archive and drag the application to wherever they please and are ready to go.
There is something written about this for wxWidgets too
MacOSX introduces a new way of putting together an application. Instead of adding a resource fork to the executable file, you can simply create a special directory (folder). This is the preferred method for OSX.