Replies: 2 comments
-
The two ways to add .h and .c files to a compiler/linker are: 1. Using the command line: To add .h and .c files to the compiler/linker using the command line, you can use the following steps:
For example, the following commands would compile and link the hello.c and hello.h files to create an executable file called hello:
Once the executable file has been created, you can run it using the following command:
If you are using a C compiler/linker IDE, such as Eclipse or Visual Studio, you can usually add .h and .c files to your project by simply dragging and dropping them into the project window. The IDE will then compile and link the files for you when you build the project. For example, to add .h and .c files to a C compiler/linker project using Eclipse, you can follow these steps:
Eclipse will compile and link the project and create an executable file. You can then run the executable file by clicking the Debug button on the Eclipse toolbar. Which method you use to add .h and .c files to a compiler/linker depends on your personal preference and the tools that you are using. |
Beta Was this translation helpful? Give feedback.
-
Not exactly sure how it works with MinGW as I think it creates native Windows executables, hence the .dll file not .so. On Linux you need to either link with rpath or have LD_LIBRARY_PATH contain the directory of your shared lib in the environment your executable runs. Try adding
in the [ToolSettings/GCC C Linker/Miscellaneous/Linker flags] field of your Exec project. |
Beta Was this translation helpful? Give feedback.
-
Hi,
On Windows 10, using eclipse for c projects I have installed the MinGW compiler. I've been able to add a static library (*.h, *.c files). I can't for some reason get a shared library to work.
I notice that for my shared library I generate a *.o file and a *.dll file but I am not creating a *.so file.
Here are the steps I'm taking:
open eclipse in new workspace
create a new c project
a) project name ->SharedLib
b) project type -> shared Library -> empty project
c) toolchain -> MinGW GCC
In SharedLib folder
a) create test.h (header file) and test.c (source file)
test.h
#ifndef TEST_H_
#define TEST_H_
void test_print(void);
#endif /* TEST_H_ */
test.c
#include <stdio.h>
void test_print(void){
printf("we have lift off");
}
build Sharedlib
a) creates Binaries -> libSharedLib.dll
create new c project Exec
a) empty project
b) add source file main.c
main.c
#include <stdio.h>
#include "test.h"
int main(void){
printf("we are on the launch pad");
test_print();
}
go into properties of Exec->Paths and Symbols->references
a) choose SharedLib, apply and close
build all and then run
I have no error messages and no output. the only thing it says is:
(exit value: -1,073,741,515)Exec.exe[C/C++ Application]
D:\workplace3\Exec\Debug\Exec.exe(9/14/23,3:05pm)
Could really use some help getting this to work.
The goal is to get this shared library automatically included in all my c projects
I believe (but am not sure) that -1,073,741,515 is the code for DLL not found but it's there!
Beta Was this translation helpful? Give feedback.
All reactions