XCode standard C++ headers suddenly not found before installing OSX update - xcode

I have a C++ project that have been compiling fine until now, I did not install any update of my system or XCode but I get this error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/wchar.h:123:15: fatal error: 'wchar.h' file not found
This file does exist on my system, so I suppose it's the CMake env paths that are no longer set up properly in the console?
Edit: if I clean my build dir and regenerate the whole CMake project, it is working again, but I still find this behaviour very unpleasant.
This has happened just when there was an available update for MacOS 13.0, and probably XCode updates going with it. But I did not install any of them yet, and my compilation is already broken.
What is happening so that the dev env is changed anyway?
I remember I had likewise issues last time there was an OS update.
Is any configuration needed to "secure" a dev env on MacOS?
Are all OS updates going to screw my XCode includes etc?

Related

XCode - creating archive fails with error «…-Prefix.pch» not found

I have a workspace with multiple targets.
Each target has its own prefix.pch file.
Prefix-Header is entered in Build Settings and Precompile Prefix Header is set to YES.
The app compiles and runs fine when I run it on my device.
There are no errors when I just build the app.
But when I try to archive it, I get a compile error saying:
No such file or directory: '/Users/me/Library/Developer/Xcode/DerivedData/myApp-dcmvkatguqcxgjfyrqcunbsfuxcd/Build/Intermediates.noindex/ArchiveIntermediates/myAppTarget/PrecompiledHeaders/SharedPrecompiledHeaders/13524936819627194222/myAppTarget-Prefix.pch'
And indeed, when I open this folder on my hd, I can't see the pch-file. There are, however, similar files there:
myAppTarget-Prefix.pch.d
myAppTarget-Prefix.pch.dia
myAppTarget-Prefix.pch.gch
I tried everything I found on SO and elsewhere, but nothing helped.
I have Cocoapods installed and use them in this project, but I don't think that error is related to that (they seem to compile fine).
XCode 12.4
Seems like I figured it out.
The culprit was a totally unrelated build-setting.
In Other C Flags my settings differed in debug and release.
I had $(inherited) in both of them, but in the release setting I additionally had -isystem - which apparently is already included in $(inherited). That caused a multitude of errors that ended with the prefix.pch not being copied...

XCode 9 unable to build - linker fails with "File not found" on object files - project builds fine in XCode 8.3.3

Here's a frustrating one. My project builds perfectly in 8.x versions of XCode, and yet in 9.x versions, it fails consistently in the linker phase, as the linker is unable to find the .o file for a seemingly random class.
For example, in one build it will be unable to find the intermediate object file for my UIWindow subclass:
In other builds, other files may be identified as the culprit, with the same "file not found" linker error.
So, clearly there is a disconnect in the linker phase. I can understand that. But I cannot make it work to save my life.
Here's what DIDN'T work:
• Deleting derived data
• Cleaning and option-cleaning
• In the .swift file inspector, removing the file from the target and re-adding to target
• Renaming the target
• Deleting the supposedly erroneous files from the project, and moving to trash, then re-adding the files to the project and target.
• Switching advanced workspace settings for Build Settings from "XCode default" to "Legacy"
• Updating XCode from 9.0 to 9.0.1
• Deintegrating Cocoapods and reinstalling them
Jeez.
So, none of the usual suspects are at play here.
Additional details :
• When I look in the folder specified in the linker error message, the .o files are NOT THERE. (Are they not being created? Is there a setting for that?)
• Using Mac OS High Sierra on a MacBook Pro Retina 15
So there's my conundrum.
Does anyone know why XCode 9 would either not be creating .o files, or would be unable to find those files, for a project that build perfectly in previous versions of XCode?
Thanks!
The only solution I found was admittedly pretty painful. I created a new project and then re-imported all the files and dependencies into the new project. Then setup all the build settings, etc. At that point the project was back to building and working fine.
If this happened again, I would try deleting the .xcworkspace file and re-generating it with pod install first before starting a new project.
May this not happen to you.

Create custom Platform and SDK for Xcode 8.3+

I'm trying to create a custom .platform and SDK in Xcode 8.3 and higher.
I am ultimately attempting to update the old DarwinBuild build system so that I can compile a few of the Apple open source components. DarwinBuild used to use this technique in order to be able to compile against a different set of headers and libraries without having to chroot.
DarwinBuild includes a setup script, installXcode32, that creates a new .platform under Xcode's Developer/Platforms directory, and a new sdk under the platform's Developer/SDKs directory. It also creates an Info.plist and SDKSettings.plist in the right spots. This script needs some updating to work with Xcode 8.3.
I know this is unsupported, but that doesn't matter in this case. After all, Apple published the original script...
I updated the original installXcode32 script to work with the new Xcode paths (/Applications/Xcode.app/Contents/...), and it produces the new .platform, Info.plist, and SDKSettings.plist, and they're all symlinked to the right spots. However, xcodebuild -showsdks now produces this error:
xcodebuild: error: Initialization failed.
Reason: Required content for platform darwin is missing.
I know it's an issue with the Info.plist and SDKSettings.plist files. I have tried copying the entire MacOSX.platform directory, and changing the names in the .plist, and I get the same error.
Does anyone know enough about Xcode and platforms to know what is required to get Xcode 8.3+ to recognize a "new" Platform and sdk?
Many thanks!
I have successfully done this with Xcode 9.4, pretty much like you did. I changed:
CanonicalName
PLATFORM_NAME
DisplayName

Library not found OpenCV

I'm on mac 10.7.5, using xcode 4.6.2 and working with the OpenCV 2.4.3 library. I went through the process of making the build directory with the cmake files in terminal and did the download.
I added the .dylib files in Xcode and changed the header path, changed C++ Library to libstdc++, but when I compiled I got this error :
ld: library not found for -lopencv_calib3d.2.4.3
clang: error: linker command failed with exit code 1
I have libopencv_calib3d.2.4.3.dylib added in the project so I have no idea what else it needs.Any ideas?
If your "make back-end" is Cmake you should stick to using it. Local config changes in Xcode can "secretly" be overwritten when the cmake is rerun (which for example happens after you make changes to it) creating weird build errors and forcing you to remember all the manual changes you made.
Your problem seems to be that the generated project doesn't seem to know where to look for opencv.
Assuming you installed opencv using macports you should add a line saying
link_directories(/opt/local/lib)
to your CMakeLists.txt. (if you installed it using brew, or compiled it manually just replace /opt/local/lib for /usr/local/lib or the path to your compiled libraries)
Also make sure to link against opencv_calib3d instead of opencv_calib3d.2.4.3 (unless you have a very particular reason for bypassing this, but that usually means that something else is weird in the setup :) )
Final pointer that you might already know of: As you are already using Cmake you should add the libraries to link against using TARGET_LINK_LIBRARIES(...) in Cmake rather than manually adding them in Xcode (referring to my previous argument).

Installing debug version of Qt on Mac OSX

I need to step through the Qt code to help solve a bug in my C++ application. I've downloaded qt-mac-opensource-src-4.5.2.tar from here and followed the install instructions that came with this:
unpacked the file to /tmp.
typed ./configure -debug.
typed make.
typed sudo make install.
edited the PATH environment variable as instructed.
set the DYLD_IMAGE_SUFFIX environment variable to _debug.
This installed Qt and my Qt application runs, but I still can't step into the Qt code.
I'm using Xcode 3.1.3 and tried changing the Executable Info to "use debug suffix when loading frameworks". This generated a lot of warnings like:
warning: Could not find object file "/private/tmp/qt-mac-opensource-src-4.5.2/src/corelib/.obj/debug-shared/qmalloc.o" - no debug information available for "global/qmalloc.cpp".
warning: Could not find object file "/private/tmp/qt-mac-opensource-src-4.5.2/src/corelib/.obj/debug-shared/qnumeric.o" - no debug information available for "global/qnumeric.cpp".
and also a lot of non-qt related warnings.
I'd shutdown the Macbook Pro overnight, which I can only assume clears the tmp directory as the unpacked file is no longer there.
I think I could fix it by rebuilding Qt without frameworks, but this is more of a work-around than a fix that will probably come back to bite me. I'm also a bit reluctant to do this, when each rebuild takes between 3 and 4 hours.
Alternatively, would downloading the binaries and debug libs work?
I'd be grateful for any suggestions on what I'm missing and how I address this.
Thanks.
With the help of Qt support, I've now resolved this.
There were a couple of issues:
The Qt debug "make install" doesn't currently generate dSYM files for the _debug stuff. They've raised a bug about this. To get round this:
4a. cd /usr/local/Trolltech/Qt-4.5.2/lib
4b. Type /usr/bin/dsymutil -o QtGui.framework/QtGui_debug.dSYM QtGui.framework/Versions/4/QtGui_debug
4c. Repeat for each Qt framework.
The tmp directory does indeed get wiped on each reboot. To get round this:
7- Copy the entire contents of /tmp/qt-mac-opensource-src-4.5.2 to a new directory ~/Qt .
I also added both the frameworks and source code to the Xcode project.
Have a look at this http://doc.trolltech.com/4.5/debug.html
There is a section especially for debugging under MacOSX and Xcode...
I guess you need to generate a makefile with debug option using qmake !
In OS X 10.6 and 10.6.1, setting DYLD_IMAGE_SUFFIX to _debug will cause problems. Hopefully this will be addressed by a future update of OS X 10.6.

Resources