Xcode 9.4.1 Could not build module and redefinition of module - Can't Build - build

Encountering this issue in Xcode, solutions I've tried:
Enabled modules to YES and NO
Reinstalled Xcode 9.4.1 by deleting 9.4.1 and ~/Library/Developer
Downgraded command lines tools to 9.4.1
Downgraded Cocoapods to 1.4.0 from 1.5.3
I'm at a loss at this point can someone point me to the right direction here? I've already spent an entire day on this. Other projects build fine though.

I SOLVED IT!
XCode was adding the following Header Search Paths:
/usr/include/libxml2 recursive
/usr/include/libxml2 non-recursive
But libxml2 is already included in the SDK from XCode.app via $(inherited) search path so everything was conflicting.
Removed those two /usr/include/libxml2 paths at the top of my folder hierarchy fixed it!
Thank the XCode gods.

Error: redefinition of module
I got redefinition of module when was working on own framework and added a first .m file (as a part of Cocoa Touch Class) and created module.modulemap file. Please note that this error is shown even if you do not add a path into Module Map File
To solve this issue I just renamed a module.modulemap to ModuleName.modulemap

Try removing Command-line tools and build your project
sudo rm -rf /Library/Developer/CommandLineTools
To Reinstall:
xcode-select --install

Related

'wchar.h' file not found

I know about this question: macOS 'wchar.h' File Not Found
but it did not help me. I've tried reinstalling xcode, reinstalling command line tools, restarting the system. wchar.h file is in place, but the compiler does not manage to find it. What else could I try? Maybe it is sysroot related? Any way to fix that?
macbooks-MacBook-Pro:Rack euphorbium$ sudo make
c++ -Iinclude -Idep/include -Idep/lib/libzip/include -DVERSION=dev -MMD -O3 -march=core2 -ffast-math -g -Wall -DARCH_MAC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -DAPPLE -stdlib=libc++ -std=c++11 -stdlib=libc++ -c -o build/src/app.cpp.o src/app.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' [-Wmissing-sysroot]
In file included from src/app.cpp:1:
In file included from include/app.hpp:2:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/vector:265:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd:90:
/Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h:119:15: fatal error:
'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
make: *** [build/src/app.cpp.o] Error 1
since wchar.h exists both in the xcode app, and in the /Library/Developer/CommandLineTools I think that it looks for it in some completely unrelated folder.
I had the same problem after upgrading to macOS High Sierra. A project which was compiling before stopped working with this error. In my case, the project files had been generated by the CMake application. The solution was to run CMake, 'Delete Cache', and 'Configure' the project again. This corrected the sysroot directory reference in the make files to point to the new SDK and the error was resolved.
I've got the same problem. I was able to fix it by using a symbolic link.
This is what I made :
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
sudo ln -s MacOSX.sdk MacOSX10.07.sdk
Then enter your root password.
NB: you have to adapt the last line with required sdk.
For any one struggling with this on MacOSX Mojave this answer solves it. In short:
Go to the terminal and run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg This will bring up the prompt to install Xcode tools.
After that's done got to the terminal and run sudo xcode-select -s /Library/Developer/CommandLineTools
My system is macOS Mojave, and I've fixed this problem by running this command line:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
It was caused by incorrect sysroot, (set for an older mac os version) set in makefiles.
If you are using CLion, follow these steps :
Click on CMake at the bottom center of your IDE
Click on the Settings Gear Icon at the left
Click on Reset Cache and Reload Project
Took me 3 hours to find this solution.
FYI this project was running fine on Bug Sur 11.3 but failed to build after I upgraded to Big Sur 11.4
Set an environment variable
SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
and reopen Terminal. This solves the header not found issue.
To see where the compiler finds headers, run with -v
clang -v test.c
For my case, this problem result from that MacOS changes the headers's path.
Check this note: MacOS release note.
So the solution is to make the compiler can find those headers.
My macOS version is Catalina 10.15, and XCode Version 12.4. For this version, it seems that /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg is not provided anymore and thus the sulotions above do not work for me.
This method saved my night: Fixing C++ compilation bugs for the MacOS Catalina upgrade. Note that if you follow its steps and errors that some global symbols are not found arise, do not modify the LIBRARY_PATH as it says.
I did something dumb but it did fix the problem... Not sure if it will work for your computer though.
Here is what I did:
I originally installed c++ using Homebrew on my MacBook on Mojave... so I had to manually install the Xcode CommandLineTools using the installer found at /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg . Then I copied the "c++" folder contents from to folder /Library/Developer/CommandLineTools/usr/include/c++/v1 to the folder where I want the missing file to be, at /usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0 , while replacing files with the same names.
The trick worked, since now the missing file "wchar.h" is right where it should be... Your settings is probably not the same, however, I am afraid.

CMake error no CMAKE_C_COMPILER could be found using Xcode and GLFW

I'm trying to follow this tutorial to get started with OpenGL: http://www.learnopengl.com/#!Getting-started/Creating-a-window and it requires downloading glfw and CMake.
I have set the downloaded glfw folder as the source code folder and I have created inside that folder another one called "build" which I then set as the build one for the binaries, as the tutorial asks.
I click on "Configure" and I select XCode as the Generator, since I'm on a Mac.
The problem is that when I try to configure the project CMake gives me this error:
The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
Configuring incomplete, errors occurred!
See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeOutput.log".
See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeError.log".
I've already read this question, but as far as I can understand, it doesn't have what I need:
CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
If you have installed Xcode or Command Line Tools for Xcode, try this:
sudo xcode-select --reset
This happened to me with Xcode10 / Cmake 3.12 after installing Homebrew. Running sudo xcode-select --reset fixed it for me.
Did you install Xcode and Xcode Commandline Tools?
xcode-select --install
If you have Xcode Commandline Tools installed, you should no longer be receiving the xcrun is missing error.
How did you install Cmake? Once you have ensured that Xcode Commandline Tools is installed, please completely remove Cmake from your system and reinstall it. You have a screwed up configuration. There are ways to debug and fix it without a clean install, but since you are new to this, it will be the easiest and lest frustrating way.
Failing that if you do have Xcode Commandline Tools installed, hstdt suggested trying this:
sudo xcode-select --reset
This error means CMake cannot find your standard C/C++ Compiler, looks like you'll need to export the environment variables yourself. you can find the path of your C/C++ compiler with:
xcrun -find c++
xcrun -find cc
Then afterwards when you have the paths, create two variables inside the gui. If you are running it from the cline, it would be something like
cmake -D CMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -D CMAKE_CXX_COMPILER="/path/to/your/cpp/compiler/executable" ...
On a fresh Xcode install the command line tools complain about agreeing to the EULA which build tools don't like. Which you can do with:
sudo xcodebuild -license
If you are on a Mac computer and have Homebrew, you can simply upgrade cmake, forcing the compiler to be reconfigured:
brew upgrade cmake
In my case, I needed to install CMake from CMake official site, download the .dmg, install it and then add the CMake folder the system's PATH.
Before the installation, the output of which cmake is /usr/local/bin/cmake.
After the installation it should be something like /Applications/CMake.app/Contents/bin/cmake.
This has solved the issue for me.
I get exactly this error if ccache is enabled on my machine. Disabling ccache fixed the problem for me.
To check if ccache is enabled, print the systems variables CC or CXX:
echo $CC
echo $CXX
This prints something like the following: ccache clang -Qunused-arguments -fcolor-diagnostics. (CC or CXX are typically overridden by the .bashrc or .zshrc file.)
To disable ccache, use the following:
CC=clang
CXX=clang++
Then rebuild the cmake project:
cmake -G Xcode <path/to/CMakeLists.txt>
Apparently, it is possible to use CMake's Xcode generator also in combination with ccache, as is described here. But I never tried it out myself.
I got this error when I had an invalid value set for CMAKE_OSX_SYSROOT. I was trying to give it the name of the SDK e.g. "macOS 10.13". Setting it to the full path of the SDK resolved the issue.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
Compiler detection appears to be broken with Xcode 10 and older versions of CMake. I know that it broke for me with CMake 2.2 and upgrading to the latest (2.13) solved it for me. It was working fine with Xcode 9 and it broke with the upgrade. I tried the other solutions (all good depending on your situation) but upgrading CMake fixed the issue.
If you are on CLion and facing this issue try changing the C and C++ compiler location inside Toolchains settings to the latest one. the default GCC installation directory is /usr/local/Cellar/gcc/...
after I upgrade Xcode to new verison, I met this error, then I upgrade my cmake version, problem solved.
For anyone coming to this question nowadays from google, my problem was fixed via
xcodebuild -runFirstLaunch
I found this by inspecting CMakeFiles/CMakeError.log

Trouble installing Boost C++

Right now, I am trying to install boost on my computer, a Mac running Mavericks. I have downloaded and decompressed boost into the directory
$HOME/local/src/
After decompressing, I moved it to a new directory inside the boost source directory:
tools/build/v2
I then executed
./boostrap.sh --with-toolset=gcc
This all went fine. The next step is where the problems start: in the src file, I executed the following command:
tools/build/v2/boost_1_57_0/b2 install --prefix=PREFIX --toolset=gcc --with-program_options --with-filesystem
It then returned the following error:
Unable to load Boost.Build: could not find "boost-build.jam"
---------------------------------------------------------------
BOOST_ROOT must be set, either in the environment, or
on the command-line with -sBOOST_ROOT=..., to the root
of the boost installation.
It says it can't find boost-build.jam, but I open up the folder in Finder and I see boost-build.jam right there in my boost_1_57_0 folder. What can I do to execute this command? Am I doing something wrong? If it runs correctly, I should have a PREFIX/include directory with header files for boost. What can I do to get this? Here is a link to the site for Boost if that will help:
http://www.boost.org
Also, I have already found this page on how to install Boost:
How do you install Boost on MacOS?
Will the method this user describes give the same result that the code above would if it was functioning properly? Thank you in advance.
Install brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then do:
brew install boost-build
After that you will have the bjam executable in /usr/local/bin/bjam.
Thank you to elyase for his response. I have also found a way to solve the problem posted above that doesn't use brew. I was making the mistake of making a new tools/build/v2 folder in my src folder--however, I was supposed to cd into the tools/build folder already in the downloaded boost folder. Also, in the newer versions of boost, there is no v2 folder--so just use
tools/build/b2 install --prefix=PREFIX --toolset=gcc --with-program_options --with-filesystem
Hopefully this will help people who are new to Mac (like me) who are having similar problems.

Boost "no such file or directory"

I'm trying to set up my Code::Blocks work environment on a new computer and I'm having some problems. It's been a long time since I first did this, and now when I open my major project Boost is causing me problems.
I'm fairly new to C++ still and fixing this type of problem is something I have limited experience with.
When I open my project and try to compile it, I get this error:
fatal error: boost/algorithm/string.hpp: No such file or directory|
At this part of one of my header files:
#include <boost/algorithm/string.hpp>
I placed the Boost v1.51.0 library at C:\boost since that is where I'd had it on my other computer. My project is set to search that directory for additional includes but it doesn't seem to be finding the files?
My project used an older version of Boost previously but I doubt that's an issue.
I'm not sure how difficult it is to debug this problem with this limited information so if there's anything else I can provide please let me know.
I'm using Code::Blocks, and have just set up minGW and Visual C++ 2010.
In Ubuntu use
sudo apt-get install libboost-dev
Ensure that you have installed boost-devel package
In Centos execute as root:
yum install boost-devel
then
root#centos6 /]# find / -name boost
/usr/include/boost
/usr/lib64/boost
[root#centos6 /]#

Mac OS X Lion and Xcode upgraded: missing headers and libs

After upgrading to Lion, and upgrading Xcode, make can't seem to locate headers and libs. I looked in /usr/include. The only thing in there was 'parallels-server'. So, I renamed /usr/include to /usr/include.old, and made a symlink to:
/Developer/SDKs/MacOSX10.6.sdk/usr/include/
This is pretty evil. But, make can now find headers. Still can't locate libs (e.g., lcrt1.10.6.o).
What is the correct way to solve both the include and lib problems?
Thanks!
After downloading Xcode 4 from the App Store, try running "/Applications/Install Xcode.app".
From me, just downloading the Xcode Command line tools did the trick. (For that, of course, I had first to install Xcode itself, which I installed trough App Store.
Start Xcode
Open Xcode→Preferences...
Select the Downloads tab
Install the Command line tools
That installs a few packages, see /var/db/receipts. The package that contains /usr/include is com.apple.pkg.DevSDKLeo.
I don't think xcode-select is needed, but I had run that command before I downloaded the Command line tools, so I don't know for sure.
To get Xcode to populate the /usr/include directory, run the following command:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
You may need to install the Xcode Command Line Tools within Xcode for this to work. Open the Preferences menu, then under Downloads install Command Line Tools.
The above answer by njamesp also addresses the following error:
configure: error: C compiler cannot create executables
I received this error when trying to compile code on my 10.7 system after setting it up from a 10.5 time machine, so I assume the wrong version of xcode was installed on my system.