Exporting C Functions for Use in C

Hello.. I have crate a new project that is a Dynamic Link Library here are my .c and .h files look like:

main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
// test4.c
#ifndef __MAIN_c__
#define __MAIN_c__

#include "test4.h"

int addition(int x, int y)
{
    int result;
    result = x + y;
    return result;
}
#endif 


test4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
// test4.h
#ifndef __TEST4_h__
#define __TEST4_h__

#ifdef BUILD_DLL
#define TEST4_API __declspec(dllexport)
#else
#define TEST4_API __declspec(dllinport)
#endif

TEST4_API int addition(int x, int y);

#endif // __TEST4_h__ 


and this is another project I want to use my dll:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Addition

#include <windows.h>
#include <stdio.h>
#include "test4.h"

int main()
{
    int a, b, c;

    printf("\n   Input a:   ");
    scanf("%d", &a);
    printf("\n   Input b:   ");
    scanf("%d", &b);

    c = addition(a, b);

    printf("\n\n   The result is:   %d", c);

    return 0;
}


I use code::blocks and I did link the .a library in the cmpiler settings but that doesn't work.
It gives me 1 error "test4: No such file or directory.
Maybe I didn't link correctly the librarie?
Please help me..
Last edited on
#define TEST4_API __declspec(dllinport)
It's dllimport.
Dohh... @!@.. I really need to take a brake.. That looks like lack of sleep.. I can't even spell correctly dllimport, and I was having even an Warning:
dllinport attribute directive ignored
<-- and I didn't even read that misspell.. What to say I am a big mess....

Thanks to you helios now I can go off to bed.. :D
Topic archived. No new replies allowed.