Xcode C++ standalone files aren't compiled - c++

Just started using c++ and I've built a little test program. All that happens is that a blue square follows your mouse around in a window. The problem is, that the image used doesn't seem to be IN the actual build file. If I delete the image from the images folder after the file is built, or send the build file to another person, the square doesn't show up.
I've searched around for answers but didn't find anything like this.
EDIT: I'm using SFML and just chose "SFML App" as a template.
EDIT AGAIN: Maybe it's because the image path is /Users/*/Desktop/ObjectiveCTests/Test/player.png. I'm not sure how to link it any other way. I've tried a lot of different paths.

Have you checked which build phase Xcode thinks your image file is part of?
You can find this out by clicking on your project, and then selecting the "Build Phases" tab, and then selecting your target. You should see a list of different build phases, each of which has several files in it. You want to make sure your image is part of the "Copy Bundle Resources" phase, not something else like "Compile Sources".
Take this with a grain of salt--I'm new to Xcode myself, but just had almost the exact same problem with my own project (except in my case it was a glsl fragment shader, not an image file, that wasn't getting bundled correctly.)

Related

Visual Studio 2017 - Changes not being built when specific source file changes

I have been working on a simple C++ OpenGL application in Visual Studio (using glfw, glew, glm libraries as well), and some time last night I started having issues when debugging my code, and only when making changes to one file. I can't remember what caused it so I will just describe the situation.
The way I am testing is by toggling a line to rotate the camera every frame to be commented out. So for example I comment out the line, the camera continues to rotate after hitting F5 to debug. I manually right click->rebuild (just building doesn't work), hit F5, and now the camera no longer rotates which is the expected result. Additionally, if I add a breakpoint in my camera class file (and only that file), I get an error message if I don't rebuild:
This is most likely because the file that is built does not have the changes from the current source code file.
Everything is working as expected if I make changes in other files, or add breakpoints. The current way I have the source structured is "main.cpp" includes "loophelp.h" which includes "Camera.cpp" (the problem file). Things I have tried:
Under "Build and Run" uncheck "Only build startup projects..", set the first drop down to "Always build", and the second drop down to "Do not launch"
In configuration manager, make sure "Build" is checked for the project for the correct configuration and platform
Create a new file with identical source code as "Camera.cpp", delete "Camera.cpp", and use the new file instead (adding it to the solution and renaming all references to "Camera.cpp"
Restart Visual Studio, restart my computer
Create a completely new solution+project and reuse the source files
I found this question which seems to be a similar problem but none of the answers worked for me or the OP:
Visual Studio need to rebuild solution for every change

How do I turn my C++ code into a .app file? [duplicate]

I am building a C++ OpenGL card game in Xcode 4.3.3, with the intention of running it on both 64-bit and 32-bit Macs, which is not my problem. My problem is that I have reached a point in the development of the program where I would like to test that it works on a different 32-bit Mac (mine is 64-bit) without having to install Xcode. This, obviously, requires me exporting it as an .app. I can find and run the exported Unix Executable File from my project, after some cd'ing, through Terminal, but that is undesirable for me and the intended audience of the program. I have trawled the google and Stack Overflow, looking for anything to help me, but all the things mentioning Archiving seem to have been unsuccessful with my particular project, and I think that's because it's a C++ command line tool project. So, can someone please help me export my project as a .app?
Thanks in advance.
The simplest way of doing this would be to create a Cocoa project, go to 'build phases' and remove all the objective-c frameworks from the 'link with libraries' build phase, remove any objective-c files added by the template (app delegate, etc.) and then replace main.c with your main.cpp file.
There's nothing really special about a Cocoa project except for the fact that it links against Cocoa and calls NSApplicationMain() from its main() function.
There are also a bunch of .plist entries used by Cocoa which you'll no longer need. But they won't affect the way OS X treats your application.
I'm searching for an XCode Settings solution but here's my current way to create an app:
You have to take your binary file (let say myapp) and put it in "MyApp.app/Contents/MacOS/myapp" then it can now be launched as a .app. That's a trick.
Just go to the targets folder in the file navigator on the left, and there will be an executable listed there. Left click on that executable and click "show in finder". (I'm describing from memory so I may have the exact details wrong.) The file path is ridiculously long (there is an arbitrary alphanumerical pathname involved, I have no idea why), so you probably won't be able to find it with the command line.
If you want you can change the extension of the file from nothing to ".app", it shouldn't affect the nature of the file at all. Also if you want a custom icon, you can "get info" on it in the finder, then click on the icon in the info window, and use Cmd-V to paste it in (obviously you have to have your icon copied to the clipboard). There is also a way to do this inside of Xcode, but I don't remember it.

Visual Studio - unsure about exporting projects

I'm new on here, but not a total beginner to programming. I got a book on creating a 2D DirectX game engine so I could expand my programming knowledge, however I am new to C++ and DirectX itself, so I'm afraid I'm a bit clueless on working with multiple project files and headers. I decided to develop my game engine in a proper development environment, so I got VS2013 Professional though the Dreamspark program.
As I said, I haven't worked with something like VS before, so I'm hitting issues with getting my game engine running and I'm not sure what to do. The book said that if I get all my code down correctly (in 3 .cpp source files, 3 headers and 1 main .cpp source file to initialize my engine in a blank game project) the program should compile fine, and it does. The issue is that I only get the resultant .obj files and the project's static library file to appear in my project folder. I don't know what I have to do to get the project to compile the executable needed to actually run this 'blank game' with the engine.
The actual project solution was taken from the disk which came with the book, I wrote my code on top of that solution as my own was causing linker errors. The project properties show that the project is defined as a .lib project, so how is this supposed to work?
I apologize if this is a simple problem, but I'm only used to working with 1 file console applications in C, this is a big jump for me but I'd like to understand how I'm meant to get an .exe created from this project, I would appreciate it if someone could explain to me how this sort of .lib project works. I can post the code if it's necessary, but there's 7 files of it so it's quite long. Thanks!
Solution 1:
As the project contains a main.cpp it looks like it is not meant to be a library-project.
In VS2013 you can switch the type of a project by
In your Solution Explorer (on the left side by default) rightclick onto the project
Select the item Properties from Context Menu (should be on the bottom)
Select the category General
In the section Project Defaults change the Configuration Type to Executable (.exe)
Solution 2:
It could be possible that the executable is stored somewhere else after a successful build. Check what is configured as output directory:
In your Solution Explorer (on the left side by default) rightclick onto the project
Select the item Properties from Context Menu (should be at the bottom)
Select the category General
In section General there should be an Output Directory defined (At the top of the configuration). Per default it should be something like $(SolutionDir)$(Configuration)\
I'm using VS2013 Express, but it should work with Prof too. I'm also using a German edition, hope I translated everything well.

SFML not loading image (Possibly due to placing in wrong place?)

I'm not sure whether I'm doing something stupid or visual studio is doing something wrong.
I've never really used C++ with VS before, but I managed to get SFML working, and now I cannot load images.
This is how I put the image in the project:
However when I write:
if (!tileTexture.loadFromFile("ConceptTile.png"))
return EXIT_FAILURE;
It returns EXIT_FAILURE.
Can anyone give an answer to why this isn't working?
If it helps that png file isn't appearing anywhere in the debug directories, just dlls, exes, and pdbs.
I've looked online to try to find out where I am supposed to put images but I can't find any articles or help no matter what keywords I type.
Make sure you change the file properties within the project to copy it to the output directory. By default (and without further paths given in the string) SFML should look for the file in your working directory. You don't have to add image files to your project, if you ensure they're at the right place. Also make sure to not include them as resources (as SFML won't be able to load them without some additional code).
Open Windows Explorer and move to the folder that contains the C++ files and paste the image there and it shall work or make a folder and change the directory in code, for example, if you name the folder images :
(!tileTexture.loadFromFile("images/ConceptTile.png"))
return EXIT_FAILURE;
and it shall work.

Beginner questions regarding to "building a library", in Xcode on iPhone specifically

I have never been clearly understand all these linking/building/dependency business. Now, I am trying to build the FreeType library (which is in C++), into the *.a library file for the iPhone (because another library I am trying to use, openFrameworks, would depend on FreeType).
I know that to compile C++ with iPhone I simply need to rename *.cpp to *.mm. (I have tried with some simply programs in main() and it works) But how can I build the library in Xcode then ? (without the main() I suppose)
On the other hand, it would be great if you guys could recommend some books or documents on such linking/building topics, which I found myself most confused about.
PS. I have already got the paid version of Xcode and some sample apps compiled onto the iPhone.
Renaming .cpp files to .mm would mean they'll be treated as Objective-C++ code rather than C++ code. I don't think that'd be a good idea, even if it should still work. Besides, FreeType is written in C, not C++.
Google for "compiler linker" and you'll find quite a few documents on how they work. That should help for documentation.
It's entirely possible to compile static libraries for the iPhone; what you can't do is compile dynamic libraries or frameworks - you could, but it's not encouraged.
Open your project
In the source/target browser, select the "Targets" node (with the little red and white target icon).
Right-click on the node, and in the popup menu select "Add", followed by "New Target".
A dialog opens. On the left hand side, there's an iPhone OS and a Mac OS X section. The iPhone OS section should already be selected; if not do so.
You should have three choices of targets, one of it is a static library. Select it, click OK.
Give the library a name in the next page. Click finish.
Your "Targets" node has includes a child for your static library now. You can add sources either via the file menu, or by dragging it onto the "Compile Sources" child node.
Hope that helps.
First, you do not need to rename any files to compile C++ code for the iPhone. Secondly, you'll want to create a separate project for the library. It looks like the iPhone target types don't include "static library", so you might need to create a Mac OS X project and modify it to output an ARM .a file. Not trivial, but probably doable.
Alternatively, if you're not going to be using this code in a lot of otherwise unrelated projects, you could include the source files directly into your App project. Collect them all into their own group, and you'll hardly know they are there.