I'm a bit of a beginner with using ubuntu/C/SDL, so i'm unsure how to do this.
I have a project where i have to simulate a bird flock with the boids algorithm. I have done the algorithm, in the respect that you could put in a target array (e.g. a 2 number array containing the X and Y position of the target point) as input, and you get the position of each member of the flock as output. Put this in an infinite loop, and the positions of the birds will be continuously updated.
I'm now supposed to use the mouse pointer to get that target array. I've been supplied with a SDL framework somebody else has programmed. The instructions to get it working where:
Change the values in the makefile for LIBS INCLUDES and CXXFLAGS, with the values found by typing sdl-config --libs, and sdl-config --cflags into the command window.
If i type sdl-config --libs into the command window, i get:
-L/usr/lib/i386-linux-gnu -lSDL
Typing sdl-config --cflags yields:
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
I typed those in as posted below, but i cant compile the main program. Compiling with "gcc main.c -o exe" gives the error message:
main.c:4:17: fatal error: SDL.h: No such file or directory
compilation terminated.
I also tried to execute the makefile with ./Makefile, and get a list of errors starting with:
./Makefile: line 1: CXX: command not found
./Makefile: line 4: LIBS: command not found
./Makefile: line 5: INCLUDES: command not found
./Makefile: line 6: CXXFLAGS: command not found
./Makefile: line 8: GETSCANS: command not found
./Makefile: line 9: GETSCANS_OBJS: command not found
How do i get it working?
main.c:
Ok, apparently you have to type "make" into the command window aswell.
Related
I am working on a C homework assignment and I came across a simple yet specific error when creating my Makefile.
My initial Makefile was simple:
all: numbers.o
gcc -Wall -pedantic -std=c1x numbers.c -o numbers
clean:
rm *.o
For whatever reason, despite the C program compiling correctly in the terminal, I repeatedly get the following error:
gcc: error: -std=c1x: No such file or directory
Makefile:2: recipe for target 'all' failed
The problem was actually because I had copied the gcc line from a pdf file. Thanks to the comment by raspy:
For sure it has nothing to do with target name. It looks like gcc did not treat the switch as a switch, but rather as a file name. Have you copied this command from somewhere? It happens that the - is not a simple dash but some dashy-looking Unicode character, most notably converted in word processors.
Trying to compile a source code written in C.
Location of the code is: C:\Users\Chris\Documents\prog\c\learn\GOODBYE.C
In CMD I typed the code: gcc goodbye.c -o goodbye
Got this error:
gcc: error: goodbye.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
I wanted the output to be named goodbye.
How do I fix this?
Make sure that you are running gcc goodbye.c -o goodbye while you are in the C:\Users\Chris\Documents\prog\c\learn\ directory.
If the c file is named GOODBYE.c then you should run gcc GOODBYE.c -o goodbye
Enter the name of the directory in which the program is located. Like if the program is in "D" drive, then open the VS Code terminal and enter "D:" (without quotation) and hit enter, and then rerun the code like this.
what if you run gcc "C:\Users\Chris\Documents\prog\c\learn\GOODBYE.C" -o goodbye
I guess it could be the case sensitivity. Either rename the file or run gcc GOODBYE.C -o goodbye
I recently built LLVM into the following path: C:\LLVM\llvm-new-build. I then added this path to my Environmental Variables/Path, C:\LLVM\llvm-new-build\Debug\bin. I'm trying to build my LLVM project, but I'm getting some weird output from Clang:
clang `llvm-config --cflags` -Wall -Iincludes/ src/*.c -c src/*.c
clang.exe: error: unknown argument: '-wd4146'
clang.exe: error: unknown argument: '-wd4180'
clang.exe: error: unknown argument: '-wd4244'
clang.exe: error: unknown argument: '-wd4258'
clang.exe: error: unknown argument: '-wd4267'
clang.exe: error: unknown argument: '-wd4291'
clang.exe: error: unknown argument: '-wd4345'
clang.exe: error: unknown argument: '-wd4351'
clang.exe: error: unknown argument: '-wd4355'
clang.exe: error: unknown argument: '-wd4456'
clang.exe: error: unknown argument: '-wd4457'
clang.exe: error: unknown argument: '-wd4458'
clang.exe: error: unknown argument: '-wd4459'
clang.exe: error: unknown argument: '-wd4503'
clang.exe: error: unknown argument: '-wd4624'
clang.exe: error: unknown argument: '-wd4722'
clang.exe: error: unknown argument: '-wd4800'
clang.exe: error: unknown argument: '-w14062'
clang.exe: error: unknown argument: '-we4238'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/DWIN32'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/D_WINDO
WS'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/W3'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/MP'
Makefile:22: recipe for target 'all' failed
make: *** [all] Error 1
It says there are no arguments like -wd4146 etc, but I haven't passed those to the clang compiler, and a quick google search shows know helpful answers on what these mean. This is what my build file looks like:
LCC = clang
LCXX = clang++
LLVM_CC_FLAGS=`llvm-config --cflags`
LLVM_LINK_FLAGS=`llvm-config --libs --cflags --ldflags core analysis executionengine jit interpreter native`
C_FLAGS = -Wall -Iincludes/
CXX_FLAGS = -Wall -Wextra -Wno-self-assign
SOURCES = src/*.c
all: ${SOURCES}
${LCC} ${LLVM_CC_FLAGS} ${C_FLAGS} ${SOURCES} -c ${SOURCES}
${LCXX} ${LLVM_LINK_FLAGS} *.o ${LLVM_FLAGS} -o j4
-rm *.o
The output from llvm-config --cflags
-IC:/LLVM/llvm/include -IC:/LLVM/llvm-new-build/include /DWIN32 /D_WINDOWS /W3
/MP -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEP
RECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WA
RNINGS -wd4146 -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 -
wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800 -w14062 -we4238 -
D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
This question really has several layers, so I'm going to try to break this down into three parts: a discussion of what is happening inside the backticks, the unknown argument errors, and the no such file or directory errors.
What is llvm-config?
llvm-config is a tool for the LLVM infrastructure that gets configuration information needed to compile programs that need LLVM. So in response to the comment at 1, llvm-config actually is intended for use with clang when clang is used to compile an LLVM project.
The --cflags option gives C compiler flags including LLVM headers, which you saw in the output to llvm-config --cflags. You said
"It says there are no arguments like -wd4146 etc, but I haven't passed those to the clang compiler"
But by putting it in backticks, your shell took the output from llvm-config --cflags and pasted it into your original command. So you did include those arguments, you just didn't realize it!
I will also note that the output from llvm-config is highly dependent on your build system and the version of LLVM. For example, when installed on Ubuntu Linux 14.05, LLVM 3.5 with GNU Make and Ninja generators, the output from llvm-config --cflags is:
-I/.../llvm-3.5.0/llvm/include -I/.../llvm-3.5.0/build/include -fPIC -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-comment -ffunction-sections -fdata-sections -g -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
It noticeably doesn't include any of your offending options like -wd4146 or -wd4180 nor any reference to Windows or preprocessor arguments.
What are those weird options like /DWIN32, /D_WINDOWS, /W3, and /MP?
/D defines a preprocessing symbol for a source file, in this case WIN32 and _WINDOWS. 2
/W3 directs MSVC to display level 1, level 2 and level 3 (production quality) warnings. 3
/MP causes MSVC to create multiple instances of itself and attempt to build the project in parallel. 4
The problem is that they're passed to the compiler's arguments prefixed with a forward slash (notice that all other options were passed with a hyphen). As a result, your build is attempting to handle those as file names, as indicated by the resulting errors, for example:
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/DWIN32'
Why it's looking in C:/Program Files (x86)/... is up to some aspect of your LLVM installation and/or your operating system. I'm going to guess it's the last location in your execution path or it is your present working directory.
What are those weird options like -wd4146 and -wd4180?
Those are options to disable certain warnings emitted for MSVC. For example, C4146 is "unary minus operator applied to unsigned type, result still unsigned" and C4180 is "qualifier applied to function type has no meaning; ignored"
Here's an example of doing the exact same thing, but from inside a GNU Make file instead of from the command line (look at the block beginning if (MSVC))
So why isn't my project building?
I can't answer this authoritatively without inspecting your LLVM build. However,
Unknown argument: You've discovered an incompatibility between your version of llvm-config and clang. You noted that you added C:\LLVM\llvm-new-build\Debug\bin to your path, but that doesn't assure that the binary actually executed for each of llvm-config and clang came from the same location. If you had previously installed a canonical, pre-built binary of clang for generic compilation usage, its location will be earlier in your path than C:\LLVM\llvm-new-build\Debug\bin. It's unlikely that llvm-config was included in your pre-built binaries. The reason this matters is that if there's a mismatch between versions, the required include flags generated by llvm-config might not match the required include flags needed by clang. You can verify that execution path shadowing is not happening using which on Unix-like machines and where.exe on Windows machines after Windows Server 2003. We expect that they will both reflect that the execution path is in fact C:\LLVM\llvm-new-build\Debug\bin. If not, there's your problem. I believe that this is what created the issues with options like -wd4146 and -wd4180, etc.
No such file or directory: When you built LLVM, cmake detected you were building on Windows, and produced Visual Studio generator files. Meanwhile, your project appears to use some sort of GNU Make-like build system. See here for more discussion of selecting generators at installation. I believe that the mix between MSVC and another GNU Make-like build system is what created the issues with options like /DWIN32, /D_WINDOWS, /W3, and /MP.
I could ran clang with command line and i thought my clang is the default one.
I could ran command like this.
clang -cc1 -analyze -analyzer-checker=debug.DumpCFG a.c
I want to find the source code from clang/lib/StaticAnalyzer/Checkers,but i cannot find the clang folder.
I have tried to search it with finder,ended failure.
Is there any shell command to find where is the command stored?
The file location is here:
/usr/local/llvm/tools/clang/lib/StaticAnalyzer/Checkers/
or
/opt/local/libexec/llvm-x.x/include/clang/StaticAnalyzer/Checkers
by an ls command you can find all the source codes int his list:
https://github.com/CTSRD-CHERI/clang/tree/master/lib/StaticAnalyzer/Checkers
Hope that's what you're looking for!
I am trying to implement a graphic userinterface to my c-programs. To that i have installed the GTK3.0-pacakge to my computer and followed the tutorial. But I am not able to compile a simple c-program that shows a 200*200 px window.
According to the tutorial one should compile like this:
gcc base.c -o base ‘pkg-config --cflags --libs gtk+-3.0‘
Where base.c is the actual program and pkg-config is the program in the bin-folder that tells the compiler where to find the header-files and libraries.
If I just test if the pkg-config-file is there I write its name in the cmd-window:
pkg-config
I get the following answer:
Must specify package names on the command line
So I actually have this config-file.
But when I try to compile base.c with the above syntax that is
gcc base.c -o base pkg-config --cflags --libs gtk+-3.0
I get the following errors
gcc: error: pkg-config: No such file or directory
gcc: error: unrecognized command line option '--clfags'
gcc: error: unrecognized command line option '--libs'
gcc: error: gtk+-3.0: no such file or directory
So why do I get these compilation errors?
Have I missunderstood what is shown in the tutorial? Is the compilation syntax just an abbreviation of what one should do?
You've just wrongly understood the tutorial. In you string disappeared the back ticks which are vital.
That means, the right line is
gcc base.c -o base `pkg-config --cflags --libs gtk+-3.0`
Compare to your (wrong) line:
gcc base.c -o base pkg-config --cflags --libs gtk+-3.0
All the staff starting with pkg-config is an independent command, not a flag for gcc.
Back ticks tell the shell to run its contents in a subshell and substantiate the result of the command run in the gcc command line.