Export C library to Windows dll - c

So I have source code written in C for the LibIdn2 library. I am looking to port it into C# but running in to some issues along the way and would appreciate some help.
Installed Cygwin along with Make and GCC G++ packages
Successfully able to run the./configure command on the source directory
After this, running the "make" command produces an .exe file.
I have been trying to get a .dll file created but cannot seem to do so using gcc compiler. The command I am running is:
gcc -shared -o idn2.dll src/idn2.c
but it complains that it cant find the header files referenced in the idn2.c source file.
I have checked that in the idn2.h file, dll_Export is defined.
Any ideas how should I proceed? I need to get a dll.

Related

Linking libraries with a MinGW project in VS code

I am using MinGW version 4.5.2 on windows 10. I am trying to link multiple libraries to a project in VS code. When I try run this command: g++ main.c -o main.exe -I"C:\\Users\\USER\\Programming\\OPenGL Library\\glfw\\include\\glfw3.h" -L"C:\\Users\\USER\\Programming\\OpenGL Library\\glfw\\lib-mingw-w64\\". I get a compile error: main.c:2:24: fatal error: GLFW\glfw3.h: No such file or directory What is wrong with the command above that gives this linking error. As far as I can tell I have pointed MinGW to the library and specified the header file. I am not sure what else I need to add to the command for link the GLFW library as well as other libraries such as GLEW or glm.
If your include directive looks like
#include <GLFW/glfw3.h>
you need to supply a path to a directory which itself contains a directory named GLFW.

Build commands needed to run Wine programs from IDE

I’ve recently done a git clone of the wine repository at https://github.com/wine-mirror/wine and downloaded the folders to (~/repo/wine/). I'm trying to run Notepad, but don't know how. I am assuming that to build and compile it, I would need to run main.c from the notepad folder. I’m running GCC v 8.3.0 on Raspbian/Linux 10
With the repo downloaded as shown above, what build commands would I need to run notepad’s main.c from Geanie (or any, currently using Geanie) IDE? Can a single compile and/or build command let me run notepad from Geanie, or am I missing something?
Other details (not needed if what I thought I was going to do can't be done):
I wanted to try to run main.c at (~/repo/wine/programs/main.c), but don’t know how to get GCC to view all of the necessary header files. In my execution instructions window in Geanie, I have
gcc -Wall -c “%f” /home/pi/repo/wine/include
and my build instruction (it won't compile, so this isn't anything I've even gotten to work with yet...)
gcc -Wall -o “%e” “%f” /home/pi/repo/wine/include
When I attempt to compile, I get:
Stdio.h:11:10: fatal error: corecrt_wstdui.h: No such file or directory.
#include <corecrt_wstudio.h>
I went over to the stdio.h and attempted to add a build instruction here as well that also targets the include folder (which is the supposedly missing file), but it won’t compile.
Using cpp -v, I can see my include paths for GCC are as follows:
#include”...” paths:
#include<...> paths:
\usr\lib\gcc\arm-linux-gnueabihf\8\include
\usr\local\include
\usr\lib\gcc\arm-linux-gnueabihf\8\include-fixed
\usr\include\arm-linux-gnueabihf
\usr\include

How to compile a C program using a library

I'm fairly new to programming in C. For my thesis I have to use the library "Libquantum" from the site http://www.libquantum.de/. I write my code in notepad and compile using the command window. I downloaded mingw and compile with gcc.
For normal C programs everything works fine. I use, for example, the command gcc -o HelloWorld HelloWorld.c and the program compiles fine. But I can't manage to compile programs where I use the library...
I downloaded the library and used the commands ./configure, make, ..., make install like they mentioned in the installation guide (https://github.com/jonbaer/libquantum/blob/master/INSTALL). After the last command the command window showed this:
I made sure to include #include <quantum.h> in the code and tried the linker flag -lquantum on different places when I try to compile but nothing works...
When I try to compile i get the following error
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lquantum
collect2.exe: error: ld returned 1 exit status
As the make install output says you need to tell the linker where the library is using a -L<path> option. The make install places the library in \usr\local\lib. If you are performing the build in MSYS, you can probably use -L\usr\local\lib, but if you have moved the file, change as necessary.
If you are building from cmd.exe (Windows's shell) rather than MSYS, you'll have to use its native a Windows path.

MinGW_w64 missing dll's

I am trying to run a C compiler with Cython in a 64-bit Windows 7 platform.
After having various problems with the C compilers from Visual studio and MinGW32, I tried to install MinGW_w64. I did the following steps :
-I downloaded and extracted winbuilds from http://mingw-w64.org/doku.php/download/win-builds, and I selected the Base GCC package with C support.
-I added C:\PATH_TO_WINBUILDS and C:\PATH_TO_WINBUILDS\bin in the PATH Windows environment variable.
-I wrote helloworld.c, a very simple C program :
#include<stdio.h>
main()
{
printf("Hello World");
}
-Then in cmd I wrote:
gcc helloworld.c -o helloworld.exe
And a dialog box pops out with the following error message :
Impossible to start program because libiconv.dll is missing on your computer. Reinstall program to correct problem.
The dll file does not appear in the lib folder of MinGW_w64. I tried to copy libiconv.a and libiconv.dll.a from the MinGW32 lib folder to the lib folder of MinGW_64, but still no luck.
Any ideas?
You need the DLL file, not the .a link library files. libiconv.dll should exist somewhere in the bin directory. If it is not there, you’ll need to get it from the internet or compile it yourself. Alternatively you could just link statically to the iconv library.
Once you find the DLL, make sure it is in one of the following locations:
* the %PATH%
* the appropriate C:\Windows\system32 or C:\Windows\SysWOW64 directory
* (preferably) next to your executable
I was able to fix the problem by downloading another version on the package on SourceForge.
Thanks!

.exe file is not being created in windows for C by cmd by gcc compiler

i am also worried about how to make u guys understand about my problem and share my experience. i am learning C.in previous, i used the Code-blocks IDE to compile and run C code.i learned that as a beginner it would better to use cmd to compile and run code than IDE. i am using windows 8. Before i was not use to with cmd, i also learned that to be a advance user and good programer i should know the use of cmd well.
After setting the environment variable started to compile c code by cmd by the following command
gcc -o "executable file name" "C source code file name"
it craete a .exe file. but no .o file. when i worked with IDE, also a .o file was found with .exe
what is the possible reason for it?
after compiling the code, i ran it by calling "executable file name".
and when checked the directory, then a .exe file was found.
but now the problem is, recently i am compiling and running code, i found that there is no .exe file created, but a file has created with unknown extension"POINTERWHILE File (.pointerWhile)"(copied from file properties). this unknown extension file is only runing by the cmd. it may be the one part of my source code file name. the code has given below and the name of source code.
Name of source code: Example184.1.pointerWhile
#include<stdio.h>
main()
{
char *p = "stop";
char str[80];
do
{
printf("Enter a String: ");
gets(str);
}
while(strcmp(p,str));
}
this program will take input until, "stop" entered.
this kind of things happened for several other files.then i copy them, to an another folder and compile and run but the same result.
i complied and run the same code form same folder and other folder by codeblocks, the result is same. the file is only running when it is in IDE.
then make an another file with other name in same directory and other, but the same code. then it is creating .exe file.
2.what may the cause for creating .exe file?
Great effort from you in learning the cmd along with C!
However, I think you're confusing the extension (name) of the file, and its contents. When you tell gcc to generate an executable file, you might want to give it a .exe extension, just like you said, assuming your source is called "myprog.c":
gcc -o myprog.exe myprog.c
This should always generate a myprog.exe file. But nothing prevents you from calling it like this:
gcc -o myprog.myFancyExtension myprog.c
You should still be able to run the program via the cmd (I didn't test that on windows though). Note that on other systems, like Linux, executable files usually have no extension at all.
Also, you're talking about how your IDE generates a myprog.o object file along with the myprog.exe executable file. To do this, your IDE is calling the compiler (gcc) twice: once to generate the .o file, and another time to generate the .exe file. There is no way to generate both files in one run of the compiler. The advantage of learning the cmd is that you will learn what your IDE is actually doing for you without telling you. The drawback is that you have to actually learn it ;)
Usually, people do not like to use gcc by hand, because as your projects grow, they will use different files and it becomes tedious to recompile them all manually. To overcome this, you will want to use a build tool, such as Make. I'm not familiar with development under Windows, so I can't recommend any specific tool. The point of those tools is that when your project has multiple source files, you only have to call the builder once, like this for Make:
make
instead of manually calling:
gcc -c myFeature1.c
gcc -c myOtherFeature.c
gcc -c myYetAnotherFeature.c
gcc -c myMain.c
gcc -o myMain.exe MyMain.o myFeature1.o myOtherFeature.o myYetAnotherFeature.o
Hope it helps

Resources