I have homebrew and its sdl2 package properly installed on OS X El Capitan, and the SDL2 headers are in /usr/local/include/SDL2, but when I use -lSDL2 in gcc and #include <SDL2/SDL.h> as in Linux, I get the error fatal error: 'SDL2/SDL.h' file not found
Why is this happening? Should I symlink /usr/local/include to /usr/include/?
you have to #include <SDL2/SDL.h>
gcc -I /Library/Frameworks/SDL2.framework/Headers -framework SDL2 your_file.c
the framework has to be in your list of library paths to be searched
Related
It seems like my gcc is broken.
When I try to install package from PyPI I have this error:
./uwsgi.h:165:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
In file included from core/protocol.c:1:
./uwsgi.h:165:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
XCode command line tools are installed:
➜ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
And gcc from brew installed:
➜ brew install gcc
Warning: gcc 8.2.0 is already installed and up-to-date
To reinstall 8.2.0, run `brew reinstall gcc`
When I try to recognize which gcc is used I have /usr/bin/gcc. I think it's XCode version.
But there is no gcc binary in brew:
➜ ls /usr/local/bin/gcc-*
/usr/local/bin/gcc-8 /usr/local/bin/gcc-ar-8 /usr/local/bin/gcc-nm-8 /usr/local/bin/gcc-ranlib-8
What can I do in this situation? How can I fix gcc?
The correct answer was in this thread: https://stackoverflow.com/a/52530212/1377912
The new Xcode doesn't provide headers by default. You should install it manually:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
As I wrote this answer, Mojave is deprecated and now is the age of Big Sur! but this problem still exists!
I don't know that following command will work on Mojave or not, but is working on Big Sur! if you still have this problem, just simply examine that.
Just set CFLAGS(for C compilers) or CXXFLAGS (for C++ compilers ) something like this:
export CFLAGS="-isysroot $(xcrun --sdk macosx --show-sdk-path) -I/usr/include -L/usr/lib -I$(xcrun --sdk macosx --show-sdk-path)/usr/include"
or
export CXXFLAGS="-isysroot $(xcrun --sdk macosx --show-sdk-path) -I/usr/include -L/usr/lib -I$(xcrun --sdk macosx --show-sdk-path)/usr/include"
It probably removes your fatal error: 'stdio.h' file not found error. If this error been removed, it might that you face to new problems, don't count them as this problem and loose your success by manipulating this! In this situation just be care about your new problems and try to fix them, one by one!
I hope this answer be useful for you
Maybe it's a stupid answer but have you tried to create and compile a very simple c file? However in my mojave system i've tried the gcc -v command and i have this output:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-
dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I’m trying to use OpenGL 3.3/4.1 on my Mac OSX 10.9 now that its finally available. I’ve been using the SuperBible 5 book and its examples to learn 3.3. I just found out that its actually only running OpenGL 2.1 though for my examples when my vertex shader started refusing to compile. I found that I need to get ahold of this GLFW library to do OpenGL windowing for me. This library will allow me to use the 4.1 version of OpenGL that OSX is capable of running. My question is does anybody have a static version of the Mac OSX 9 OpenGL library GLFW version 3.0.4 they can just send me? It is kind of a real pain trying to build the library from scratch as because it involves installing CMake and then the library code and then trying to get it all to work together and compile. I really only need the library so I can start getting OpenGL 3.3/4.1 to run.
I will suggest installing glfw via homebrew http://brew.sh/
The advantage being you can always uninstall it neatly by doing brew uninstall glfw3!
You need to have the "Command Line Tools for Xcode" and Xcode install https://github.com/Homebrew/homebrew/wiki/Installation
xcode-select --install
Once Homebrew is installed, open the terminal and run
brew update
brew tap homebrew/versions
brew install glfw3 for glfw3 OR
brew install glfw2 for glfw2
Also, if you desire an static build, use the flag --static
brew install --static glfw3
The libraries and include files will be available at usr/local/lib and usr/local/include
Now, if you have a program that relies in opengl and glfw, you'd want to compile it something like this:
gcc program.c -o myapp -framework OpenGl -lglfw3 (or -lglfw2)
If you still have some problems with the glfw header file, you can do:
gcc program.c -o myapp -framework OpenGl -I/usr/local/include -lglfw3
To build the GLFW library from source, only a few steps are required:
Download and extract the GLFW source code.
Open the Terminal.
cd to the extracted directory.
Type in cmake ., hit return.
A Makefile will be created for you.
Type in make, hit return.
After the compilation process, type in sudo make install.
The libraries will be copied to /usr/local/lib/, the header files to /usr/local/include/.
Note: You'll need a compiler suite installed to build software, this would usually be the XCode Command Line Tools package. For this, install and launch XCode from the Store or download the tools from the developer site.
If you have troubles with linker try to compile like this:
g++ youSource.cpp -I/usr/local/include -L/usr/local/lib -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo
or just:
g++ youSource.cpp -I/usr/local/include `pkg-config --cflags glfw3` `pkg-config --static --libs glfw3`
Problem
I am having an issue implementing the g++48 compiler in QT Creator. I built this compiler using MacPorts. It appears that QT Creator ignores my compiler and defaults xcode g++42. How do I properly setup the compiler to override this?
Troubleshooting
Did you install gcc/g++ correctly and is it the main one selected?
I have ensured that gcc was installed correctly and the path is correct by doing the follows:
:~ which gcc:
/opt/local/bin/g++
:~ g++ --version:
g++ (MacPorts gcc48 4.8.1_3) 4.8.1
What system are you using?
My system: Mac OSX 10.9 Mavericks. QT Creator 2.8.1 Based on QT 5.1.0.
Toolchain setup: In QT Creator I specified the custom GCC compiler by going Compilers_Add_GCC and putting in the compiler path /opt/local/bin/g++. If I hover the mouse over any of the #include lines in *.cpp then it properly displays the path /opt/local/include/gcc48/{headerName}. I suspect the problem is related to the QT Mkspecs, but I really don't understand what this is or how to write a custom one for my custom gcc installation (if necessary). Can this be explained?
Kit updated in QT Creator? The kit was updated by following the directions that here: Qt Creator use another GCC Version located in another Place
Why do you suspect g++42 is being used? This is based on the results I get from inspecting the build log file.
12:30:19: Running steps for project untitled...
12:30:19: Configuration unchanged, skipping qmake step.
12:30:19: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/usr/bin/g++ -c -pipe -std=c++11 -g -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.6 -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -I/Users/raymondvaldes/Qt/5.1.0/clang_64/mkspecs/macx-g++ -I/Users/raymondvaldes/Documents/code/untitled -I. -o main.o /Users/raymondvaldes/Documents/code/untitled/main.cpp
/Users/raymondvaldes/Documents/code/untitled/main.cpp:4:10: fatal error: 'random' file not found
#include <random>
^
1 error generated.
make: *** [main.o] Error 1
12:30:20: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: gcc48)
When executing step 'Make'
12:30:20: Elapsed time: 00:01.
and
RAYMONDs-MacBook-Air:~ raymondvaldes$ /Applications/Xcode.app/Contents/Developer/usr/bin/g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Finally, here is my simple working example:
#include <iostream>
#include <complex>
#include <cmath>
#include <random>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
and my pro file.
cache()
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp
Thank you.
I finally solved this issue and I am now able to use my MacPorts GCC48 compiler in QT Creator. As I suspected I needed to create a gcc48 mkspecs folder in the QT Directory and feed the folder name to the QT Creator custom compiler setup screen. I created "macs-g++48" folder that was copied from the generic "macs-g++" folder in "~path~QT/5.1.x/clang_64/mkspecs". I had to modify qmake.conf. I commented out
#include(../common/g++-macx.conf)
#include(g++-base.conf)
and placed their contents within quake.conf while making the following modifications:
QMAKE_CC = gcc-mp-4.8
QMAKE_CXX = g++-mp-4.8
With Xcode 4.6, under Mac OS X 10.8.2, to compile hello.c, I issued the xcrun command recommended in xcrun gcc cannot find header files but still received the error that the header file stdio.h can not be found.
$ xcrun clang --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/ -o hello hello.c
hello.c:2:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
$ cat hello.c
/* C program, Hello World */
#include <stdio.h>
int main()
{
printf("Hello World \n");
}
it should work with :
xcrun clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/
I changed my Build Settings for that project as the Base SDK was not specified. Once I changed it to OS X 10.7 (or whatever you are using should be fine), I was able to compile everything successfully without changing other build configurations.
I'm trying to compile a project which is using OpenAL on Mac OS X 10.7. If I would be using XCode I could link the OpenAL.framework, but in the directory
/System/Library/Frameworks/OpenAL.framework/
theres no subdirectory called 'Libraries'. So what should I link against?
This is just a generic answer to link frameworks in the Mac, it should work for OpenAL.framework
% gcc -framework OpenAL -o test test.c
Also see this old GCC article