How to instruct Xcode to use yasm to compile .asm files? - xcode

How can I instruct Xcode to use YASM to compile .asm files? I have a Xcode 4.0 project setup to compile C and C++ files just fine, however, Xcode doesn't know what to do with .asm files. I've already got the binary tool yasm installed, it's just a matter of instructing Xcode of using Yasm to compile .asm files.
For Visual Studio, I use the Yasm rules, and for Linux I modified the makefile. However, I do not know how to configure Xcode to use yasm.
Any ideas?

Install yasm. (MacPorts or brew or DIY)
Select the project item in the Project Navigator.
Select the target from the TARGETS list.
Select the "Build Rules" tab item.
Click "Add Build Rule" button.
Choose "Assembly files (sourcecode.asm) from the "Process" pop-up.
Choose "Custom script:" from the "Using" pop-up.
Enter the yasm build command into the script area. For example:
#!/bin/bash
/usr/local/bin/yasm -f macho32 -o ${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}/${INPUT_FILE_BASE}.o ${INPUT_FILE_DIR}/${INPUT_FILE}
Add the output file ("${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}/${INPUT_FILE_BASE}.o") to the list of output files.
The shell variables are defined by Xcode and added to the shell execution environment. I determined these instructions without any prior familiarity with yasm, so I apologize if there are any errors in my invocation. Seems to be working in my case, though.

Related

Rebuilding a wxWidgets installation with vcpkg and a modified setup.h configuration file

The version of setup.h that vcpkg uses to build wxWidgets (x64-windows) has some values I want to change. I want to make these changes and have the library rebuilt using my values.
I can't find a way to get vcpkg to rebuild the package. I can only 'remove' it and 'install' it. The 'remove' takes my changed setup.h with it, and the 'install' installs Microsoft's defaults (... and these ARE Microsoft's defaults; they are different to the defaults you get if you download the source and compile it yourself...)
Anybody know how to achieve what I want to do?
#GeoffreyArmstrong,
Why not download the source code from www.wxwidgets.org, download MSVC Community Edition from Microsoft and build the library yourself with whatever configuration you want?
Install MSVC Community 2019.
Download and unpack wxWidgets to, i.e. C:\wxWidgets-3.1.4.
Start MSVC and open C:\wxWidgets-3.1.4\build\msw\wx_vc16.sln (latest one available).
Open C:\wxWidgets\include\msw\setup.h and make those modifications.
In MSVC select "Build -> Batch Build...", click "Select All", then click "Build"
Go drink some coffee.
When the build finishes, open C:\wxWidgets-3.1.4\samples\minimal\minimal_vcN.sln
Build it and run it.
What could be simpler?
Thank you

Compile & Run CLion Project from Terminal

I am trying to create generally-accessible compile & run instructions for my CLion project, but can't find the exact terminal command it uses to execute the program (it's makefile, I would assume). From the project directory in the terminal, how would I do this?
The directory looks like this:
I will add a little bit to #Stanley F.'s excellent answer.
FROM the root of the CLion project, this is what works for me. I generally run with a debug profile. The same can be reproduced for release.
When cmake loads its project, it runs
cmake -Bcmake-debug-build -H. ${CMakeOptions}
where CMakeOptions is stored in CLion at
CLion->settings->Build,Execution, Deployment->CMake->[profile]->CMake Options
My general cmake build option is
-DCMAKE_BUILD_TYPE=debug -DSYTEM_ARCH=Linux-gcc5.3.0-x86_645 -CMAKE_CXX_STANDARD=14
[Note the lower-case d for 'debug'. If I do not use this, my system will not work. I wish that CLion did not default to 'Debug']
So, to reproduce what CLion creates upon project reload, I run
rm -rf cmake-debug-build
cmake -Bcmake-debug-build -H. -DCMAKE_BUILD_TYPE=debug -DSYTEM_ARCH=Linux-gcc5.3.0-x86_645 -CMAKE_CXX_STANDARD=14
Then, to build the project, I run
cmake --build cmake-build-debug --target all
Please note that when I run the first cmake command (from CLion or the command line), cmake pulls in lots of libraries from other "precedent" projects as part of the processing of my CMakeLists.txt file. If anything in one of those precedent projects changes, I will not pull them in anew, unless I physically delete the entire cmake-build-debug/ directory. None of CLion's reset tool menu items from my experience will delete that file.
If I am running these commands from the CLion menus, then I have to physically delete the cmake-build-debug/ directory as well (if I have a change in one of the external libraries that I want to pull in).
CLion currently only supports CMake projects. So you have to invoke the CMake executable with the appropriate parameters for your project.
At first, you can delete the cmake-build-debug folder, since this is auto-generated by CLion, which itself invokes CMake. It only contains temporary files.
So your build environment basically contains the 3DTable.c, 3DTable.h and CMakeLists.txt files. At least this is what I get from the screenshot.
To build the project from command line, first navigate to the source directory. Then invoke CMake:
cd <source path of Project_1>
cmake -Bbuild -H.
cmake --build build --target all
Notes:
build is the directory, where CMake will generate temporary files and the build artifacts.
The -H. option tells CMake, where the CMakeLists.txt file is located, which in this case is the current working directory.
The library / executable for your project will be located within the build directory
CLion can tell you, you don't need to hunt.
CMake command line
Select tools\cmake\reload cmake project.
The command line is shown in the CMake window.
Build command line
Select build\build project.
The command line is shown in the messages window.
Example
Mine look like this:
"C:\Program Files\JetBrains\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2021.2.2/bin/ninja/win/ninja.exe" -G Ninja -S C:\some_application -B C:\some_application\cmake-build-debug
...
"C:\Program Files\JetBrains\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" --build C:\some_application\cmake-build-debug --target all -j 9
Reminder
If using Visual Studio you still to specify which environment you are using. Typically this involves using the VS command prompt or executing one of the premade scripts to set up the environment variables. See here.

How to setup meson with Qt creator

I normally use Qt creator with cmake to program C++ projects. Lately I read quite a bit about meson and it's simplicity and I like to test it. This example explains how to setup meson.
When using meson, I like however to still use Qt creators shortcuts for building (ctrl + B) or running (ctrl + R). How can I configure Qt creator to build a meson project, when I'm using a "generic project"?
Meson is currently not directly supported by Qt Creator. There is a bug report requesting that: https://bugreports.qt.io/browse/QTCREATORBUG-18117 and I am considering to actually implement that.
For the time being I use meson via the "Generic Project". Go to "New File or Project", "Import Project" and there "Import Existing Project". That gets you a dialog where you can select the files that your project consists of.
After that is done you will need to edit "projectname.includes" and add the include directories (one per line) into that file. Then you need to edit "projectname.config" and add defines (one per line) there.
Finally you will need to edit the build configuration and call ninja instead of make there.
With that it works reasonably well for my small project.
Until the QtCreator supports directly meson.build project files, I find this python2 script useful to create QtCreator generic project files: https://github.com/mbitsnbites/meson2ide
with meson and ninja in your PATH, this should work:
$ meson builddir
$ python2 meson2ide.py builddir
this generates a .creator project file in builddir (if you get an error about "mesonintrospect" not found, try this PR: https://github.com/mbitsnbites/meson2ide/pull/1)
To make CTRL+B work properly, In QtCreator build settings, remove the make build step and add a custom build step with the path to the ninja executable, and add the command line arguments
3>&1 1>&2 2>&3
Those redirect allow QtCreator to capture build errors in the "issue" panel.

Can't find file executable in your configured search path for gnc gcc compiler

My problem is that code::blocks error message tells me that it can't find file executable in the search path for gnc gcc compiler. Although, I don't know what that means. Also I typed out some code:
#include <iostream>
using namespace std;
int main(void) {
cout <<"Hello World" <<endl;
return 0;
}
I can't build it or run in code::blocks. What do I need to do?
I went on line but I got some answers that are way over my head. I was able to use code::blocks once before I installed Visual studios express 2013. Visual studios didn't work right either. It kept asking me to repair or uninstall every time I tried to open it. So I deleted it along with code::blocks. Now that I re-installed code::blocks I still can't get to work right.
This problem with compilers is taking up all my time and I can't practice learning programming because I can't get any compiler to work right. I need some help, please.
I'm guessing you've installed Code::Blocks but not installed or set up GCC yet. I'm assuming you're on Windows, based on your comments about Visual Studio; if you're on a different platform, the steps for setting up GCC should be similar but not identical.
First you'll need to download GCC. There are lots and lots of different builds; personally, I use the 64-bit build of TDM-GCC. The setup for this might be a bit more complex than you'd care for, so you can go for the 32-bit version or just grab a preconfigured Code::Blocks/TDM-GCC setup here.
Once your setup is done, go ahead and launch Code::Blocks. You don't need to create a project or write any code yet; we're just here to set stuff up or double-check your setup, depending on how you opted to install GCC.
Go into the Settings menu, then select Global compiler settings in the sidebar, and select the Toolchain executables tab. Make sure the Compiler's installation directory textbox matches the folder you installed GCC into. For me, this is C:\TDM-GCC-64. Your path will vary, and this is completely fine; just make sure the path in the textbox is the same as the path you installed to. Pay careful attention to the warning note Code::Blocks shows: this folder must have a bin subfolder which will contain all the relevant GCC executables. If you look into the folder the textbox shows and there isn't a bin subfolder there, you probably have the wrong installation folder specified.
Now, in that same Toolchain executables screen, go through the individual Program Files boxes one by one and verify that the filenames shown in each are correct. You'll want some variation of the following:
C compiler: gcc.exe (mine shows x86_64-w64-mingw32-gcc.exe)
C++ compiler: g++.exe (mine shows x86_64-w64-mingw32-g++.exe)
Linker for dynamic libs: g++.exe (mine shows x86_64-w64-mingw32-g++.exe)
Linker for static libs: gcc-ar.exe (mine shows x86_64-w64-mingw32-gcc-ar.exe)
Debugger: GDB/CDB debugger: Default
Resource compiler: windres.exe (mine shows windres.exe)
Make program: make.exe (mine shows mingw32-make.exe)
Again, note that all of these files are in the bin subfolder of the folder shown in the Compiler installation folder box - if you can't find these files, you probably have the wrong folder specified. It's okay if the filenames aren't a perfect match, though; different GCC builds might have differently prefixed filenames, as you can see from my setup.
Once you're done with all that, go ahead and click OK. You can restart Code::Blocks if you'd like, just to confirm the changes will stick even if there's a crash (I've had occasional glitches where Code::Blocks will crash and forget any settings changed since the last launch).
Now, you should be all set. Go ahead and try your little section of code again. You'll want int main(void) to be int main(), but everything else looks good. Try building and running it and see what happens. It should run successfully.
Just open your setting->compiler and click on the reset defaults and it will start work.
* How to Download and install CodeBlocks.* ( I have already downloaded )
***How to solve the CodeBlocks environment error.
Go to "Settings"----"Compiler"----"Selected compiler"( GNU GCC Compiler ).
Then, Selected "Toolchain executables".
Now, "( C:\Program Files (x86)\CodeBlocks\MinGW )"
See Video : https://youtu.be/Tb1VnXs60Lg
I had also found this error but I have solved this problem by easy steps. If you want to solve this problem follow these steps:
Step 1: First start code block
Step 2: Go to menu bar and click on the Setting menu
Step 3: After that click on the Compiler option
Step 4: Now, a pop up window will be opened. In this window, select "GNU GCC COMPILER"
Step 5: Now go to the toolchain executables tab and select the compiler installation directory like (C:\Program Files (x86)\CodeBlocks\MinGW\bin)
Step 6: Click on the Ok.
Now you can remove this error by follow these steps. Sometimes you don't need to select bin folder. You need to select only (C:\Program Files (x86)\CodeBlocks\MinGW) this path but some system doesn't work this path. That's why you have to select path from C:/ to bin folder.
Thank you.
For that you need to install binary of GNU GCC compiler, which comes with MinGW package. You can download MinGW( and put it under C:/ ) and later you have to download gnu -c, c++ related Binaries, so select required package and install them(in the MinGW ). Then in the Code::Blocks, go to Setting, Compiler, ToolChain Executable. In that you will find Path, there set C:/MinGW.
Then mentioned error will be vanished.
Uninstall/Remove your current codeblocks compiler.
Install codeblocks using this link that contains GCC compiler files: http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup-TDM-GCC-481.exe.
Now go to : Settings > Compiler.... > ToolChain Executables Tab
CLICK on Auto-detect button and then click OK button. Now just restart CodeBlocks and start writing your codes and use the Build and run option. It will RUN normally.
Fistly, Code Blocks is not a compiler. It is just an integrated development environment.
So, you must show the path of your compiler at first, (if you dont have a compiler you have to download an install, it is not difficult to find. f.e. GCC is good one.)
If code blocks could not find automatically the path of compiler it is an obligation to show it yourself.
But when you install, probably Code Blocks automatically find your compiler.
Enjoy.
This simple in below solution worked for me.
http://forums.codeblocks.org/index.php?topic=17336.0
I had a similar problem. Please note I'm a total n00b in C++ and IDE's but heres what I did (after some research)
So of course I downloaded the version that came with the compiler and it didn't work. Heres what I did:
1) go to settings in the upper part
2) click compiler
3) choose reset to defaults.
Hopefully this works
I'm a total noob but I reinstalled over the codeblocks giving me these "Can't find file executable in your configured search path for gnc gcc compiler" errors by downloading:
codeblocks-20.03mingw-setup.exe
(IMPORTANT: make sure it has the "mingw" in the file download name, that has the compiler build that is required to compile the code which doesn't automatically comes with the main codeblocks editor software download because codeblocks already assumes you already have another compiler installed on your computer {visual studio 2019 or such}).
Then when I created a new project (console application) and used the defaults to quickly test it out.
It gave me errors.
So I went to Settings > Compiler > Selected Compiler set to: GNU GCC Compiler > Click on the "Tooolchain executables" tab > Click on Auto-Detect > Should say "C:\Progam Files\CodeBlocks\MinGW" > Click OK.
Build and run a simple hello world code.
Should work! If not, look for the "MingGW" in the C:\Program Files\CodeBlocks and select it.
Here's an easy way for Windows users.
Uninstall the existing codeblocks from your system.
Restart system.
Go to http://www.codeblocks.org/downloads/26
Download the codeblocks-16.01mingw-setup.exe file. It includes the GCC/G++ compiler and GDB debugger from TDM-GCC (version 4.9.2, 32 bit, SJLJ).

Create multiple executables in XCode

There are various versions of this question but I havnt been able to find what Im looking for.
I have a bunch of cpp files in the OpenCV samples directory. I would like to create a project in XCode that can compile and build all the executables. I opened a new project, added all the sample source files, included the correct header files and the right link paths and then got stuck because I dont know how to make the project build and link executables for each relevant cpp file. Im guessing Im doing this completely wrong so any help would be appreciated.
In Xcode 4, click on the Project icon in the navigator which should bring up a Projects and Targets section in the main pane. There should be an "Add Target" button at the bottom. Just add a new target and then specify which source files you want in the "Compile Sources" section in the "Build Phases" tab.
Xcode 3 is should be similar. Add a new target and tell it which source files to use.
HTH
You don't need XCode to build samples, OpenCV on Mac OS X makes use of cmake to generate makefiles which, in turn, are being consumed by gcc.
Please read:
http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port
So, assuming you have cmake installed, in OpenCV source directory run:
sudo cmake -D BUILD_EXAMPLES=ON -G "Unix Makefiles" .
You have Makefile in your 'samples' directory now and can compile samples:
cd samples
sudo make
The sample binaries will be put in the 'bin' directory. VoilĂ !

Resources