I have a project (here) that works both on Linux and intel MacOS, but in my Mac m1 it doesn't. Whenever I try to compile it, I get the following errors (ops.: I'm using vscode m1 native):
pedrohaccorsi#MacBook-Air-de-Pedro dev % make
g++ -o app src/glad.c src/AudioManager.cpp src/Character.cpp src/SceneManager.cpp src/Source.cpp src/Sprite.cpp src/stb_image.cpp -g -Iinclude -F/Library/Frameworks -lglfw -ldl -framework SDL2 -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2_mixer -I/Library/Frameworks/SDL2_mixer.framework/Headers
In file included from src/AudioManager.cpp:1:
include/AudioManager.h:1:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
^~~~~~~~~~~~
1 error generated.
In file included from src/Character.cpp:1:
In file included from include/Character.h:1:
In file included from include/Sprite.h:6:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
^~~~~~~~~~~~~~
1 error generated.
In file included from src/SceneManager.cpp:1:
In file included from include/SceneManager.h:3:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
^~~~~~~~~~~~~~
1 error generated.
src/Source.cpp:10:17: warning: using directive refers to implicitly-defined namespace 'std'
using namespace std;
^
In file included from src/Source.cpp:12:
In file included from include/SceneManager.h:3:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
^~~~~~~~~~~~~~
1 warning and 1 error generated.
In file included from src/Sprite.cpp:1:
In file included from include/Sprite.h:6:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
^~~~~~~~~~~~~~
1 error generated.
make: *** [app] Error 1
Before hand I ran these three commands and they worked successfully, no errors nor warnings at all, so I assumed it was all working fine.
brew install glfw
brew install sdl2
brew install sdl2_mixer
Anyone has any ideas?
My issue was partially solved. There were two problems, GLFWand SDL2.
GLFW
The fix was the same proposed in this thread; in a nutshell it consists in:
$ nano ~/.zshrc
> export CPATH=/opt/homebrew/include
> export LIBRARY_PATH=/opt/homebrew/lib
This will tell the compiler to look for things in opt/homebrew, which is where homebrew for m1 installs the packages, instead of usr/local.
SDL2
I downloaded the two .dmg files from the websites below
https://www.libsdl.org/download-2.0.php
https://www.libsdl.org/projects/SDL_mixer/
Then I went to the downloads and copied the .framework directory from both downloads and pasted into /Library/Frameworks.
This solved those errors from before, that the system could not find the includes, but a new error showed up: symbols not found for architecture arm64. I decided to quit trying and just removed the sound out of my game (it was a college assignment, no biggie in taking features out).
On MacOS Monterey 12.6 I fixed the issue by installing xcode, then installed with homebrew:
glew
glfw3
xquartz
brew install glew glfw3
brew install --cask xquartz
Then I pointed to the X11 folders and sample OpenGL program compiled.
The github source code was taken from: https://github.com/zamirmf/OpenGLOnMac
For example:
clang -o testopengl main.cpp \
-L/opt/X11/lib -L/opt/homebrew/lib \
-I/opt/X11/include -I/opt/homebrew/include \
-lglfw -framework OpenGL
Related
Clearwater sprout project contains a lot modules. One of them is libevhtp, at Github libevhtp.
INCLUDE (CheckIncludeFiles)
CHECK_INCLUDE_FILES(sys/tree.h HAVE_SYS_TREE)
if (NOT HAVE_SYS_TREE)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/tree.h.in ${CMAKE_CURRENT_BINARY_DIR}/compat/sys/tree.h)
endif(NOT HAVE_SYS_TREE)
In wsl Ubuntu, system does not have sys/tree.h, so it uses build/libevhtp/compat/sys/tree.h to compile. And it compiles successfully.
In CentOS, system does not have sys/tree.h either, but instead of using build/libevhtp/compat/sys/tree.h, cmake gives an error:
Building C object CMakeFiles/cmTryCompileExec667563402.dir/CheckIncludeFiles.c.o
/bin/cc -o CMakeFiles/cmTryCompileExec667563402.dir/CheckIncludeFiles.c.o -c /home/tiina/clearwater/sprout/build/libevhtp/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/home/tiina/clearwater/sprout/build/libevhtp/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:2:22: fatal error: sys/tree.h: No such file or directory
#include <sys/tree.h>
I checked CMakeCache.txt in both WSL and CentOS, they are the same:
HAVE_SYS_TREE:INTERNAL=
I am trying to get g++ to compile a program that uses Magick++, however despite installing the libraries, I get the below error when compiling the program with g++ WallFade.cpp `Magick++-config --cxxflags --cppflags --ldflags --libs` -o WallFade:
fatal error: Magick++.h: No such file or directory
4 | #include <Magick++.h>
| ^~~~~~~~~~~~
compilation terminated.
When I set an absolute path to the header file by replacing #include <Magick++.h> with #include "/usr/local/include/ImageMagick-7/Magick++.h" I then get the following error:
/usr/local/bin/Magick++-config: line 47: --cflags: command not found
/usr/local/bin/Magick++-config: line 50: --cflags: command not found
/usr/local/bin/Magick++-config: line 53: --libs: command not found
/usr/local/bin/Magick++-config: line 56: --libs: command not found
In file included from WallFade.cpp:4:
/usr/local/include/ImageMagick-7/Magick++.h:10:10: fatal error: Magick++/Include.h: No such file or directory
10 | #include <Magick++/Include.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
I'm assuming I need to run some command to link the header files to g++, but I'm not sure what that command would be (currently running Arch Linux).
Install following package libmagick++-dev
packman -S libmagick++-dev
I think this is the way to install it on Arch.
I am using MacOS 10.15. Since the clang shipped with MacOS does not include clang-format. I installed another pre-built clang binary from here. I have added the binary file path to my PATH variable.
export PATH="$HOME/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin:$PATH"
I tried to compile a simple program:
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << "Hello world!\n";
return 0;
}
using the following command:
clang++ hello.cpp -o hello
I got the following error:
In file included from hello.cpp:1:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/iostream:37:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/ios:214:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/iosfwd:95:
/Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/wchar.h:118:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
I found that wchar.h bundled with this pre-built package is in the following directory:
/Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/include/c++/v1/
So I added the -I flag:
clang++ -I /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/include/c++/v1 hello.cpp -o hello
The error still persists.
If I use clang++ shipped with MacOS, I have no problem compiling the source code:
# the following works without any error
/usr/bin/clang++ hello.cpp -o hello
I have seen post here, here, and here, but the solutions do not apply.
You got clang-format improperly. Reset the system to the state before you installed another pre-built clang binary. Then use Homebrew to install clang-format
brew install clang-format
clang+llvm-10.0.0-x86_64-apple-darwin is not suitable to your Mac. It depends on system frameworks that are not available, so you get the error finding wchar.h in a system framework. When you install clang+llvm-10.0.0-x86_64-apple-darwin you ignore framework dependencies. Homebrew will care about dependencies.
I have a 16inch MacBook pro with latest updates (macOS Catalina 10.15.2 (19C57)), the latest version of XCode and Command line tools for macOS (the tools being installed in the usual path /Library/Developer/CommandLineTools/).. Not sure if this is relevant to my issue or not, but I also have the latest version of JetBrains’s CLion installed on my machine (running without issues).
Here is the problem: When trying to build a project with cmake, the build FAILS, giving me this error message:
In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootDFile.cc:25:
In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootD.hh:28:
In file included from /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error:
'string.h' file not found
#include_next <string.h>
1 error generated.
error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc' failed with exit status 1
make[2]: *** [bindings/python/python_bindings] Error 1
make[1]: *** [bindings/python/CMakeFiles/python_target.dir/all] Error 2
make: *** [all] Error 2
and this is probably related to my C++ compiler not having the correct path to the include files. To see what the issue could be, I’ve made a simple C++ file and I tried to compile it.
main.cpp
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
int main()
{
std::string name = "NAMEX";
std::cout << name;
}
First, I tried with the usual “g++” and it worked just fine:
basavyr#Roberts-MacBook-Pro stringTestCLANG % g++ main.cpp
basavyr#Roberts-MacBook-Pro stringTestCLANG % ./a.out
NAMEX% basavyr#Roberts-MacBook-Pro stringTestCLANG %
Then, I tried with /Applications/Xcode.app/Contents/Developer/usr/bin/g++ main.cpp and it worked just fine.
Checking the version of “g++” on my machine gives me this:
g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
This is interesting, because I was expecting that the default compiler is installed in /usr/bin/ instead. Going into that “InstalledDir” folder I saw that there is no “g++” binary, but only “clang++” and “c++”, so I tried to compile with both and it turns out that both compilers are giving the same error as the one in the project that I trying to build:
basavyr#Roberts-MacBook-Pro stringTestCLANG % /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ main.cpp
In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error:
'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
basavyr#Roberts-MacBook-Pro stringTestCLANG %
Since I also have Command Line Tools installed, I tried to compile with both “g++” and “clang++” from /Library/Developer/CommandLineTools/usr/bin/ and the first one compiles successfully, while the second one throws the same error with regards to the string header file.
basavyr#Roberts-MacBook-Pro stringTestCLANG % /Library/Developer/CommandLineTools/usr/bin/c++ main.cpp
In file included from main.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:505:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string_view:176:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__string:57:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cstring:61:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
So, I assume that when I build that project with cmake, it is using one of these compilers (from the XCodeDefault.xctoolchain folder) and it has issues with the string header.
Q1: How can I solve this issue? Q2: And also, why does my “g++” installation directory points to this XCodeDefault.xctoolchain instead of “/usr/bin/’ or “/Applications/Xcode.app/Contents/Developer/usr/bin/”. Is there a way to change that in macOS?
Thank you in advance
I am trying to build the PrintFunctionNames example from clang.
However I get the following error:
[mac-osx:clang/examples/PrintFunctionNames] osx% clang++ -std=c++0x PrintFunctionNames.cpp
In file included from PrintFunctionNames.cpp:15:
In file included from /usr/local/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from /usr/local/include/clang/Frontend/FrontendAction.h:22:
In file included from /usr/local/include/clang/Basic/LLVM.h:22:
In file included from /usr/local/include/llvm/Support/Casting.h:19:
/usr/local/include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
System Info:
clang version 4.0.0 (http://llvm.org/git/clang.git 6197d01def79876e2c1670ced871e10b12c36241) (http://llvm.org/git/llvm.git 24f7cd87f70ddcc91d50f77e405420c0c27853fd)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /usr/local/bin
OSX 10.11.6
Edit 1:
on making the changes suggested by Alex, I start getting header issues. On fixing it via includes, same error is thrown again
% clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I../../../clang/include -I../../../../include -I../../../../../build/include
In file included from PrintFunctionNames.cpp:15:
In file included from ../../../clang/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from ../../../clang/include/clang/Frontend/FrontendAction.h:22:
In file included from ../../../clang/include/clang/Basic/LLVM.h:22:
In file included from ../../../../include/llvm/Support/Casting.h:19:
../../../../include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
^
1 error generated.
OS X (macOS) has a bit different approach. You can have several Xcode installed and you compile for different platforms.
You should use -isysroot option to explicitly specify against which SDK to build.
The following command should do the trick
clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
Otherwise, please check which SDKs are installed and change the value of isysroot to correspond to your setup.