I come to you with a weird problem I've been facing.
So last week, I installed llvm and libomp for a C project, and it compiled just fine with this at the start of my makefile:
CC=clang
CFLAGS = -O2 -fopenmp
CFLAGS += -I/usr/local/opt/libomp/include
LDFLAGS = -fopenmp
LDFLAGS += -L /usr/local/opt/libomp/lib
Today I meant to finish that project, I opened vs code (I don't know if that's relevant), added some code left and right, and when I wanted to compile the code again to test if everything was fine, it gave me
me#macbookPro% make
clang -c -O2 -fopenmp -I/usr/local/opt/libomp/include bubble.c -o bubble.o
bubble.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
make: *** [bubble.o] Error 1
which has left me dumbfounded since it worked just fine a few days ago.
I tried to do an export CPATH with
export CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
but I got a bunch of warning and it didn't work either.
Any help is greatly appreciated !
Info: I'm running the latest version of BigSur and VSCode.
Apparently a macOS update had uninstalled the XCode developer tools.
I ended up uninstalling llvm and libomp, and when reinstalling it told me brew didn't have CLT (use brew config to check that).
Then I ran the classic xcode-select --install then brew install llvm and brew install libomp, edited my path to include the llvm's bin and it works again.
My solution:
masOS12.3.1 monterey
"software update" --> "update commandLineTool" if push --> you can compile correctly without 'stdio.h' file not found.
Related
I tried to run this Github repository called 'Karel the Robot' for my work in university:
Karel the Robot for MacOS
I use macOS Monterey V12.2.1 and run this through an IDE called Clion. I tried to work on the projects via the built in VCS option of the IDE and also tried to simply download and open it from the desktop. Whenever I try to run the basic project (without any additions or changes made by me) I get this error:
/Library/Developer/CommandLineTools/usr/bin/cc -I/Users/nox/CLionProjects/karel/include -I/usr/local/include -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -mmacosx-version-min=12.2 -std=gnu11 -MD -MT CMakeFiles/StarterProject.dir/HelloKarel.c.o -MF CMakeFiles/StarterProject.dir/HelloKarel.c.o.d -o CMakeFiles/StarterProject.dir/HelloKarel.c.o -c /Users/nox/CLionProjects/karel/HelloKarel.c
In file included from /Users/nox/CLionProjects/karel/HelloKarel.c:10:
In file included from /Users/nox/CLionProjects/karel/include/karel.h:3:
In file included from /Users/nox/CLionProjects/karel/include/structs.h:48:
/Users/nox/CLionProjects/karel/include/config.h:1:10: fatal error: 'SDL/SDL.h' file not found #include <SDL/SDL.h>
I understand that he can't find the SDL.h file on my system so I installed and reinstalled it with brew by doing the following:
brew install sdl sdl_image sdl_ttf
and brew reinstall sdl sdl_image sdl_ttf
Nothing seemed to work for me. Can anyone help me with this please?
How can I compile a sdl project using gcc in the linux command line without using Cmake?
EDIT;
gcc SDLGAME.c pkg-config --cflags --libs sdl2
but i get error.
gcc: error: Pkg-config: No such file or directory
gcc: error: sdl2: No such file or directory
gcc: error: unrecognized command line option ‘--cflags’
gcc: error: unrecognized command line option ‘--libs’; did you mean ‘--libs=’?
#HolyBlackCat
source code --->>
#include <stdio.h>
#include <SDL2/SDL.h>
int main(int argc,char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) !=0)
{
printf("error SDL");
return 0;
}
SDL_Window* win=SDL_CreateWindow("Game",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
500,500,0);
return 0;
}
I get this error--->>
error: XDG_RUNTIME_DIR not set in the environment.
error SDL
Caveat: This isn't a total solution but some suggestions and is prefaced by top comment's and comments under OP's [now deleted] answer.
To review ...
After fixing the original issue by use of:
gcc -o SDLGAME SDLGAME.c `pkg-config --cflags --libs sdl2`
OP running the program produces:
error: XDG_RUNTIME_DIR not set in the environment.
This may be a general issue about the ubuntu install itself. Some resources for that: https://askubuntu.com/questions/872792/what-is-xdg-runtime-dir and
https://askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut
A workaround may be:
export XDG_RUNTIME_DIR=/tmp/dir
mkdir -p /tmp/dir
But, I ran the program successfully on my home system, running fedora 29 and my ubuntu system running 18.04.5
On my systems, XDG_RUNTIME_DIR was set to /run/user/1000. However, with/without the workaround and even doing unset XDG_RUNTIME_DIR worked on my systems.
However: On my ubuntu system, I had removed the standard libsdl2 package and rebuilt and installed it from the source package a year ago due to some issues I had.
So, if the workaround doesn't work, I recommend libsdl2 rebuild/reinstall from source.
Even if the standard package is working, when debugging your app, it can be helpful to be able to consult the libsdl2 source.
Note that one change I made to your app was to add a sleep(3) at the bottom so you can see the window come up.
Here is the method I used to build/install from source:
It's probably necessary to uninstall/remove the binary libsdl2 package. So, you'll have to do (e.g.)
sudo apt-get remove libsdl2 libsdl2-dev
Or, whatever the binary package is called [I forget]. But, those also came from: apt-cache search libsdl2
So, once that's cleaned out, what I did was:
Create a directory (e.g.): $HOME/aptsrc
cd $HOME/aptsrc
Download the source package [without sudo]: apt-get source libsdl2
This extracts several files (e.g. *.tar.gz, *.tar.xz, *.dsc and a directory. On my system, it was: libsdl2-2.0.8+dfsg1, but for you it may be different. Do (e.g.): DIR=$HOME/aptsrc/libsdl2-2.0.8+dfsg1
cd $DIR
Configure with: $DIR/configure
Run cmake: cmake $DIR
Run make with: make
Install with: sudo make install
Note that this comes from an internal script I created. Even after the cd $DIR, I think it's necessary to use full path on the commands [where indicated].
Now, the library should be installed under /usr/local. The output of pkg-config --cflags --libs sdl2 should reflect this:
-D_REENTRANT -I/usr/local/include/SDL2 -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2
The original output of this command would have looked like:
-I/usr/include/SDL2 -D_REENTRANT -lSDL2
This is for the standard install from the binary package, so if you still have that, the binary package may still be installed.
Otherwise, you should now be able to rebuild your app using the original gcc command. Now, it should be attached to the source built version of the library. You can confirm this with: ldd ./SDLGAME but just running it might be easier.
i install the MinGW and select those packet。
i also have using the command to check whether did i forget download some packet for install about GCC complier。
i also also have checking the path whether add the C:\MinGW\bin or not.
when i think everything is ready, i make a helloword c file for testing
#include "stdio.h"
void main()
{
printf("helloworld\n");
}
but when complies there is a error happen “stddef.h No such file....”
i knows there is a lot of posts about this issue here ,but i can't found anything way for solve this error....
i have also try to update the gcc and g++ version and make them same:
mingw-get update gcc g++
but it also doesn't work!
It is with the version mismatch of gcc and g++.
First, we need to remove both the packages by executing below command in cmd.
mingw-get remove gcc g++
Then execute install to reinstall
mingw-get install gcc g++
hope this helps!!!
I have a problem while compiling Vim 7.4 under AIX 6.1.
My options for the configure script are: "--prefix /opt/freeware/bin" and "--enable-pythoninterp".
There where no Errors while running the configure Script but when I try to run "make" I get the error message:
cd src && make first
cc -qlanglvl=extc89 -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA -DFUNCPROTO=15 -g -o objects/regexp.o regexp.c "regexp_nfa.c"
line 4410.1: 1506-046 (S) Syntax error.
make: 1254-004 > The error code from the last command is
1.
Stop. make: 1254-004 The error code from the last command is 2.
Stop.
Does anyone know what to do?
I had compiled Vim 7.4 in my home directory so I know that there is a workaround but I can't find it anymore.
AIX's built in make (based on standard AT&T make) is not compatible with the Makefiles built by autoconf tools. Use GNU make (gmake) instead. You may already have it installed (check /opt/freeware/bin), install from the Linux Toolbox for AIX set (from IBM), or from one of the websites providing prebuilt GNU tools for AIX systems (perzl, bullfreeware, etc). Just provide an alias from make to gmake, or override the use of make in the Makefile itself.
After upgrading to Ubuntu 13.10 "Saucy", Clang now gives me the error message:
clang -Wall -Werror -std=c99 -ggdb -O0 5.1.c -o 5.1
In file included from 5.1.c:1:
/usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
# include <stddef.h>
^
1 error generated.
make: *** [5.1] Error 1
BTW the header I included was stdio.h not stddef.h but I am assuming that stdio.h references or #includes stddef.h
This error appeared for me when trying to run clang-tidy without clang installed.
Installing clang fixed this error. IMO this error occurs when clang-tidy looks for headers in GCC and system paths and clang version/symlink of these headers are missing.
It's a know bug in ubuntu. Take a look here: https://bugs.launchpad.net/ubuntu/+source/llvm-defaults/+bug/1242300
It appears that a temporary workaround is to correct the symlink:
For the 3.5 LLVM toolchain it seems that the symlink
/usr/lib/clang/3.5/include erroneously points to
../../llvm-3.4/lib/clang/3.5/include, but should instead point to
../../llvm-3.5/lib/clang/3.5/include
The workaround (of course) is to manually correct the symlink.
For the 3.4 toolchain the /usr/lib/clang/3.4/include doesn't exist at
all. I have not tried LLVM 3.4 on Ubuntu so I don't know if createing
a symlink to ../../llvm-3.4/lib/clang/3.4/include will fix the
problem, but it does seem likely.
Source
Please note that I resolved the above error by performing:
$ sudo apt-get install clang
In my particular case, there is likely an issue with something in my cmake files which I haven't determined yet.
Using clang-tidy from cmake and gcc you can add the following in your CMakeLists.txt
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
This will result in the "compile_commands.json" file to contain the correct gcc includes.
The solution comes from the kitware issue tracker: Missing c++ header path in compile_commands.json
This answer is a bit off topic but this is the top hit on search engines for my specific issue