What is the function of libgcc_s_dw2-1.dll? - c

I wrote the following program in Codeblocks
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
a = 5;
b = 6;
c = a+b;
printf("Hello world!\n");
return 0;
}
for both debug and release builds. The exe files are created in the respective bin\debug and bin\release folders, and the program works fine when run from codeblocks.
However when I try to execute the exe files form bin\debug or bin\release, I get the libgcc_s_dw2-1.dll is missing from your computer. error.
Searching for libgcc_s_dw2-1.dll only brings out other posts that ask how to fix this problem, where the suggested solution is to either add the path to libgcc_s_dw2-1.dll, which is somewhere inside inthe MinGW installation, to the system path, or statically link the dll file to the program during compilation.
My question is, why is this necessary? This is a very simple hello world program. The file is in a codeblocks project and file extension is .c (main.c, so I'm guessing gcc is automatically invoking the C compiler and it doesn't have anything to do with compiling C code with cpp compiler?) and the compiler settings have been left at their default values after a fresh MinGW and Codeblocks install. Since this program is very simple I am assuming it should work the same way in any other older version compilers as well.
Then what is the use of this dll file? What is happening under the hood when compiling this program? Suppose I compile the hello world program above and distribute the exe file to my friends. How am I supposed to know that I should have statically linked the dll file during compile?

Related

OpenAL Library Linking With cMake

I'm trying to get a grasp on audio programming in C with OpenAL. I prefer CLion as an IDE to Visual Studio, but that generally means having to deal with cmake stuff and I ran into an issue regarding this. Right now I'm just trying to link the library (as in getting the definitions of the OpenAL functions) but it seems I've got something out of place. Here's the CMakeLists.txt file,
cmake_minimum_required(VERSION 3.19)
project(AudioTest C)
set(CMAKE_C_STANDARD 99)
set(OPENAL_LIBRARY "C:/Program Files (x86)/OpenAL 1.1 SDK/libs/Win64/") //OpenAL Installed here
find_package(OpenAL REQUIRED)
add_executable(AudioTest main.c)
target_link_libraries(AudioTest "${OPENAL_LIBRARY}")
The Cmake file compiles (or reloads) fine on it's own. But when I try to run this simple program,
#include <stdio.h>
#include <al.h>
int main() {
printf("Hello, World!\n");
alGetError();
return 0;
}
I end up with this,
undefined reference to '_imp__alGetError'
Could I get some pointers to what I might be missing?

My helloworld for C is compiling but the .exe file isn't running?

I coded this simple C Hello World program, but i don't know why it's not working in command line? I'm using MinGW C compiler which I downloaded per site instructions and I'm using Sublimetext for my text editor. I compiled the program fine it seems b/c the .exe file shows up, but when I try to run that file it prints
the problem seems pretty basic, my bad if it the question is amateur, just started trying to learn C.
Here's my code from Sublime text for it.
#include <stdio.h>
int main (){
printf("Hello World\n");
return 0;
}
You need to specify the directory of the executable within PowerShell. Your alternative is to launch the program through cmd.exe.
.\helloworld.exe
or
C:\Users\Zanel\OneDrive\documents\code\C\helloworld.exe
. represents current directory.

Eclipse with MinGW does not link correctly

I use the Eclipse Luna IDE for C/C++ (CDT) and MinGW for programming C with Microsoft Windows 7.
I try to write a simple program which uses KissFFT
This is not directly a library, this are only some *.c and *.h-Files.
My example program is stored at E:\Programming\Programs\Simple_FFT\
That is my example program:
#include <stdio.h>
#include <stdlib.h>
#include <tools/kiss_fftr.h>
int nfft = 1024;
int inverse_fft = 0;
int main(void) {
kiss_fftr_cfg cfg = kiss_fftr_alloc(nfft, inverse_fft, NULL, NULL);
kiss_fft_scalar timedata[nfft]; //input
kiss_fft_cpx freqdata[nfft]; //output
while (1)
{
timedata[nfft] = 0;
kiss_fftr(cfg, timedata, freqdata);
free(cfg);
}
return 0;
}
As you can see I included kiss_fftr.h.
This file on the other hand is including kiss_fft.h.
In Eclipse, I went to Properties -> C/C++ General -> Paths and Symbols -> Includes -> GNU C -> and there i added the directorys E:\Programming\Libraries\kiss_fft130 and E:\Programming\Libraries\kiss_fft130\tools
Because this are the folders where the needed header files and c files are stored.
So everything fine, not?
But now the curious thing: I can't compile the program with Eclipse. I'm relatively new to programming but as far as I know, if I include a header file and the directory is included in Eclipse, the related *.c-file should be linked automatically.
Instead I get undefinded references:
src\Simple_FFT.o:Simple_FFT.c:(.text.startup+0x3b): undefined reference to `kiss_fftr_alloc'
src\Simple_FFT.o:Simple_FFT.c:(.text.startup+0x86): undefined reference to `kiss_fftr'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: src\Simple_FFT.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
The problem is, that Eclipse is not linking the c-files of KissFFT to the included headers.
So I found two solutions to bypass this problem:
First: Compile the program manually:
gcc -o E:\Programming\Programs\Simple_FFT\Release\Simple_FFT -I"E:\Programming\Libraries\kiss_fft130" -I"E:\Programming\Libraries\kiss_fft130\tools" E:\Programming\Programs\Simple_FFT\src\Simple_FFT.c E:\Programming\Libraries\kiss_fft130\tools\kiss_fftr.c E:\Programming\Libraries\kiss_fft130\kiss_fft.c
As you can see, I included the *.c-Files "kiss_fftr and kiss_fft" manually and compilation is fine.
Second solution: In Eclipse, I went to Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> MinGW C Linker -> Miscellaneous -> Other Objects -> and added E:\Programming\Libraries\kiss_fft130\kiss_fftr.c and E:\Programming\Libraries\kiss_fft130\kiss_fft.c.
Then the program is compiling fine, too.
Both is not my intention. Because I would have to manually link every *.c-file I use in my program. What is my failure in the properties of Eclipse, that it does not automatically link the correct files together?
Would be very happy to get an answer so I can start programming correctly :)
You need to add your C files folders to the Source Locations in the Project Properties->C/C++ General->Paths and Symbols. Or, if you have your kiss library compiled (.lib or .a) you should add it in the linker section Library Search path and Libraries

Unable to link libpng or zlib in Eclipse with MinGW C linker

I'm new to external static libraries in C, and i'm having trouble adding pnglib (or any library) to Eclipse. Im using Eclipse v3.3.2 with mingw on windows 7 64bit.
I first followed these instructions to install libpng and zlib: http://wiki.openttd.org/Compiling_on_MinGW
Then in Eclipse under C/C++ Build -> Settings ->Tool Settings -> MinGW C Linker -> Libraries
I added: "png" then "z" in Libraries (-l)
and: "C:\MinGW\libpng-1.5.12" then "C:\MinGW\zlib-1.2.7" in the Library search path (-L)
If I execute the simplest code:
#include <stdio.h>
#include <zlib.h>
#include <png.h>
int main(void) {
printf("foo\n");
unsigned char header[8];
//png_sig_cmp(header, 0, 0);
return 0;
}
It works fine, however as soon as i uncomment the function, the code compiles (without error/warning), but does absolutely nothing, (not even the print statement). This happens when I use ANY function from an external library.
I assume it can read the headers but there's funny business with finding function definitions.
I have no idea where i went wrong.
I'm sure I have missed something trivial!

run c program - stdio.h where do i get it?

Looking into learning C. As I understand it when I say #include <stdio.h> it grabs stdio.h from the default location...usually a directory inside your working directory called include. How do I actually get the file stdio.h? Do I need to download a bunch of .h files and move them from project to project inside the include directory? I did the following in a test.c file. I then ran make test and it outputted a binary. When I ran ./test I did not see hello print onto my screen. I thought I wasn't seeing output maybe because it doesn't find the stdio.h library. But then again if I remove the greater than or less than signs in stdio the compiler gives me an error. Any ideas?
I'm on a Mac running this from the command line. I am using: GNU Make 3.81. This program built for i386-apple-darwin10.0
#include <stdio.h>
main()
{
printf("hello");
}
Edit: I have updated my code to include a datatype for the main function and to return 0. I still get the same result...compiles without error and when I run the file ./test it doesn't print anything on screen.
#include <stdio.h>
int main()
{
printf("hello");
return 0;
}
Update:
If I add a \n inside of the printf it works! so this will work:
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}
Your code should have preferably
printf("hello\n");
or
puts("hello");
If you want to know where does the standard header file <stdio.h> comes from, you could run your compiler with appropriate flags. If it is gcc, try compiling with
gcc -H -v -Wall hello.c -o hello
Pedantically, a standard header file is even not required to exist as a file; the standard permits an implementation which would process the #include <stdio.h> without accessing the file system (but e.g. by retrieving internal resources inside the compiler, or from a database...). Few compilers behave that way, most really access something in the file system.
If you didn't have the file, you'd get a compilation error.
My guess is the text was printed, but the console closed before you got the chance to see it.
Also, main returns an int, and you should return 0; to signal successful completion.
#include <header.h>, with angle brackets, searches in standard system locations, known to the compiler-- not in your project's subdirectories. In Unix systems (including your Mac, I believe), stdio.h is typically in /usr/include. If you use #include "header.h", you're searching subdirectories first and then the same places as with <header.h>.
But you don't need to find or copy the header to run your program. It is read at compilation time, so your ./test doesn't need it at all. Your program looks like it should have worked. Is it possible that you just typed "test", not "./test", and got the system command "test"? (Suggestion: Don't name your programs "test".)
Just going to leave this here : STILL! in 2018, December... Linux Mint 18.3
has no support for C development.
innocent / # cc ThoseSorts.c
ThoseSorts.c:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
innocent / # gcc ThoseSorts.c
ThoseSorts.c:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
innocent / # apt show libc6
(Abbreviated)::
Package: libc6
Version: 2.23-0ubuntu10
Priority: required
Section: libs
Source: glibc
Origin: Ubuntu
Installed-Size: 11.2 MB
Depends: libgcc1
Homepage: http://www.gnu.org/software/libc/libc.html
Description: GNU C Library: Shared libraries
Contains the standard libraries that are used by nearly all programs on
the system. This package includes shared versions of the standard C library
and the standard math library, as well as many others.
innocent / # apt-get install libc6-dev libc-dev
So, magic... and a minute later they are all installed on the
computer and then things work as they should.
Not all distros bundle up all the C support libs in each ISO.
Hunh.
hardlyinnocent / # gcc ThoseSorts.c
hardlyinnocent / # ./a.out
20
18
17
16
... ... ...

Resources