Create a Command Line Tool in Xcode on macOS
Contents
Create a Command Line Tool in Xcode on macOS#
This topic describes the steps needed to configure an Objective-C Command Line Tool in Xcode. These steps have been verified to work with Xcode 15.0.1, on macOS Ventura 13.5.2.
Create the Xcode project#
Open Xcode, select
Create New Project
, pickmacOS
as a platform, pickCommand Line Tool
for ApplicationSet Product Name to
enum-devices
, selectObjective-C
for language.Rename
main.m
tomain.mm
.Download the 64 bit version of PrimoBurner for C++ (macOS). The file you need will have a name similar to
primoburner-v5.0.1-demo.1-darwin.zip
except for the version number which may be different.Extract the ZIP archive in a location of your choice, then copy the
include
andlib
directories to theprimoburner
subdirectory of the Xcode project directory. The Xcode project directory is the directory that contains theenum-devices.xcodeproj
project file.You should end up with a directory structure similar to the following:
enum-devices ├── primoburner │ ├── include │ └── lib ├── enum-devices │ └── main.mm └── enum-devices.xcodeproj
In Xcode, select the
enum-devices
project in Xcode, and then the ‘Build Settings’ tab:Under Apple Clang - Language - C++, set the C++ Language Dialect to
C++20[-std=c++20]
Under Search Paths | Header Search Paths, add the
$(PROJECT_DIR)/primoburner/include
directory to the listUnder linking - General | Runpath Search Paths, add
@executable_path
to the listSet the Build Products Path to
$(PROJECT_DIR)/build
In Xcode, select the ‘enum-devices’ target, and then the ‘Build Phases’ tab:
Expand the ‘Link Binary with Libraries’ section
Add the
libPrimoBurner.dylib
from the$(PROJECT_DIR)/primoburner/lib/x64
directory.
Replace the contents of
main.mm
with this code:// // main.mm // enum-devices // #import <Foundation/Foundation.h> #pragma clang diagnostic push #pragma clang diagnostic ignored "-Weverything" #include <iostream> #include <primo/burner/pb.h> #include <primo/platform/ustring.h> #include <primo/platform/reference++.h> #pragma clang diagnostic pop namespace p = primo; namespace pb = primo::burner; int main(int argc, const char * argv[]) { @autoreleasepool { // Create engine auto engine = p::make_ref(pb::Library::createEngine()); // Initialize engine engine->initialize(); // create device enumerator auto enumerator = p::make_ref(engine->createDeviceEnumerator()); for (int i = 0; i < enumerator->count(); i++) { // create a device; do not ask for exclusive access auto device = p::make_ref(enumerator->createDevice(i, false)); if (device) { using namespace std; auto description = p::ustring(device->description()); cout << "Device : " << i << endl; cout << "Description : " << description.str() << endl; cout << endl; } } // terminate engine engine->shutdown(); } return 0; }
Restart Xcode!!! Otherwise it will not pick the new Build Products Path
Build the project ( ⌘B )
Copy the file
libPrimoBurner.dylib
fromprimoburner/lib/x64
tobuild/Debug
.Run the application in Xcode. You should see a list of all CD / DVD / BD devices that are connected to the system.
Troubleshooting#
You may get
dyld: Library not loaded: @executable_path/libPrimoBurner.dylib
or a similar message. To fix that, copy the filelibPrimoBurner.dylib
fromprimoburner/lib
tobuild/Debug
.