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Ă !
Related
I'm trying to build GLFW from source for Code Blocks. I used Cmake and it made a directory and I opened the Code blocks project file and clicked the gear to build. The only thing new in src is libglfw3.a and I'm not sure what to do with it.
I think you're following the LearnOpenGL tutorial. Actually, i tried to do the same as he recommended, but i ended up following this tutorial which is way more simple to apply https://www.youtube.com/watch?v=0WrSGMuU964&t=0s . It's using the pre-compiled binaries folder, that's why it is not using Cmake. To make it short (under windows), you only need to copy/paste the include and lib-mingw folders in your project folder. Then open your project with Code::Blocks and go in Project/Build options... . In Search directories under the compiler tab, you need to add the include directory you just copy/pasted and under the linker tab, you do the same thing with the lib-mingw dir. Now in the linker settings tab (next to search directories) you need to add glw3, gdi32, and opengl32, and that's all it should be working now :) I only wrote the tutorial in case one day it disappears from youtube :p
This was posted a while ago but I think I built the static GLFW library for linux with WSL CMake instead of Windows CMake.
I found that it is possible to create XCode project from command line with a help of CMake (are there any other options?). Is there any tool to create XCode workspace and pin projects into it?
If not, can I create it manually? My current version of XCode (7.3 beta) makes a workspace that consists of below file structure:
WORKSPACE_NAME.xcworkspace/
contents.xcworkspacedata
xcuserdata/
USER_NAME.xcuserdatad/
UserInterfaceState.xcuserstate
Content of contents.xcworkspacedata looks straightforward and I guess this is the file that pins projects into workspace.
UserInterfaceState.xcuserstate is a binary file that can be generated when workspace is opened in XCode.
Summing up, if there is no command line tool for creating workspace and pinning projects into it, can I just generate proper contents.xcworkspacedata file or should I do something more?
If your project has a CMakeLists.txt file, CMake can generate an XCode project file from it (on the command line), and you can then build it as well (from the command line).
Assuming you are currently in your project's source directory and it contains a CMakeLists.txt:
$ mkdir build && cd build
$ cmake -G "Xcode" ../
$ cmake --build .
Alternatively you can remove the -G option, it'll then generate a Makefile, and then you can do make and it will build on the command-line too, using the Xcode build tools.
The extremely helpful guidelines posted at http://www.vtk.org/Wiki/Cocoa_VTK and via the readme file by Sean McBride and Mike Jackson inside the VTK repo were slightly out of date for VTK 6.1. So in case this helps anybody, I'm posting instructions for installing VTK 6.1 on OSX 10.8 with support for the SimpleCocoaVTK Xcode project.
* Installing VTK 6.1 for OSX 10.8 with Cocoa support *
These instructions slightly modify Ryan Glover's instructions at http://www.vtk.org/Wiki/Cocoa_VTK and the README.rtf in the VTK/Examples/GUI/Cocoa/Documentation folder by Sean McBride and Mike Jackson.
Clone the VTK git repo into a directory of your choice:
cd /Users/you/
git clone https://github.com/Kitware/VTK.git
cd VTK
git checkout tags/v6.1.0
make a build directory
mkdir VTKBuild
cd VTKBuild
Run the VTK cmake script
You will now be inside /Users/you/VTK/VTKBuild, run cmake from here (using the parent directory's CMake files):
cmake ..
Edit lots of lines in the newly generated CMakeCache.txt (in the current VTKBuild directory). One issue I had was that there were error if I didn't use a full path for the CMAKE_INSTALL_PREFIX. So make sure to use "/Users/you/" instead of "~":
CMAKE_INSTALL_PREFIX:PATH=/Users/you/VTK/VTKBuild
BUILD_SHARED_LIBS:BOOL=OFF
CMAKE_BUILD_TYPE:STRING=Debug
VTK_USE_SYSTEM_ZLIB:BOOL=ON
CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64
CMAKE_OSX_SYSROOT:STRING=/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
Compile the VTK project (this might take over an hour to run!):
make
Copy headers to an include directory:
make install
VTK should now be completely installed in the VTKBuild directory and ready to use in an XCode project!
Go to your finder, navigate to Users/you/VTK/Examples/GUI/Cocoa/ and double click to open SimpleCocoaVTK.xcodeproj in XCode.
In the XCode menubar (at the top of the screen) Go to Preferences->Locations->Source Trees and use the + button to add in two source trees:
vtk-debug-include vtk-debug-include Users/you/VTK/VTKBuild/include/vtk-6.1
vtk-debug-lib vtk-debug-lib Users/you/VTK/VTKBuild/lib
Click on the XCode project and delete all the references to vtk 6.0:
In the project view, select Targets->SimpleCocoaVTK and then press "Build Phases" and then open the "Link Binary With Libraries". Delete all the files that begin with "libvtk" and end with "6.0.a"
In the file view of the SimpleCocoaVTK project, hightlight and delete all the files in the vtk-libraries folder.
Make sure the XCode file view is active. Then in the finder, navigate to /Users/you/VTK/VTKBuild/lib, and select all the files that begin with "libvtk" and end with "6.1.a". Drag these files into the folder "vtk-libraries" in the XCode file view.
In XCode, do a Product->Clean
You can now build and run the sample SimpleCocoaVTK project.
I also had to set
VTK_WRAP_PYTHON:BOOL=ON
in CMakeCache.txt
It depends on what user you are too on your machine (computer) and the permissions relevant to that user. I did a find and replace on the CMakeCache.txt file and changed all /usr/local references to /Users/myusername/Develop/VTKInstall. That way everything's at your fingertips and you don't have to change permissions on things.
When you open up the Cocoa example make sure to set in you preferences these paths (e.g. Preferences->Locations->Source Trees). Also you'll need to re-import your vtk-libraries into the project.
I'm running Yosemite with XCode 6.1.1. I hope this helps someone!
If you get error messages likes this, when trying to build VTK:
#error: garbage collection is no longer supported
make[2]: *** Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/vtkCocoaRenderWindowInteractor.mm.o] Error 1
make1: *** [[Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/all] Error 2
You need to remove a flag in the source CMakeLists.txt:
#IF(APPLE)
SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
ENDIF(APPLE)#
Either outcomment or delete it all together. Then run cmake again in an empty build directory. Check in the generated CMakeCache.txt in your build directory if it contains a key like VTK_REQUIRED_OBJCXX_FLAGS, it shouldn´t, try running cmake in an empty build directory again.
This 'bug' maybe fixed in future VTK versions.
Source: [Solved] Build Qt 5.2.1 + VTK 6.1.0 + CMake 2.8.12.2
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.
I was using classic Unix Makefile generator until I found a webpage explaining CMake could produce a nice xcode project file using "cmake -G Xcode" so I ran that command in my source directory and I get a nice xcode project. This is great but I'm facing some drawback and was wondering if there are solutions to these :
now I can't build out of tree using unix makefiles (I use to run cmake ../myproj in a build dir and then make command) this doesn't work anymore (I suppose temp files in the project dir are responsible)
some of my headers are generated by cmake (myproj.h.in became myproj.h and is include in some tests for example) but I can't find those files in the xcode project I get.
Thanks in advance for any good advice on how I can combine xcode project and unix makefile to be able to use both.
I found the answer by myself (I mean asking the good person) :
Use 2 separate build directories for each type of build files. This will ensure each build directory has the correct build files and generated files for its use.
In the add_executable() command, in addition to the source files also include the headers and generated headers for those to show up in Xcode.
You can use xcodebuild to still have a proper Xcode project and build it from the command line/shell script/Makefile, e.g.
xcodebuild -project MyProject.xcodeproj -target MyTarget -configuration Release