JaredTS486
JaredTS486

Reputation: 436

Eclipse EXPORT DLL before compile/build

I am using Eclipse Juno updated as two days ago, fresh install and installed C/C++ and linked MinGW into Windows (7 64-bit by the way). Everything works fine, i can build/compile "Hello World" and execute the file generated by eclipse.

Now i have three files, main.cpp:

#include "functions.cpp"
#include <iostream>
using namespace std;
int main(int){
    int a = mult(20,5);
    cout << "Twenty times 5 is " << a;
    cout << a << "Plus 2 is " << add2(a);
    return 0;
}

functions.cpp:

#include "header.h"
int EXPORT  add2(int num){
  return num + 2;
}
int EXPORT  mult(int num1, int num2){
  int product;
  product = num1 * num2;
  return product;
}

header.h:

#ifndef HEADER_H_
#define HEADER_H_
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
int EXPORT add2(int num);
int EXPORT mult(int num1, int num2);
#endif /* HEADER_H_ */

With this set up in the code i need a DLL file to be generated first and then used when building. If i place these files on my desktop for instance, i can /cd desktop and use this command:

g++ functions.cpp -o functions.dll -DBUILD_DLL -shared -Wl,--out-implib,libfunctions.dll.a

This creates a DLL file and also a .A File, one dynamic one static.

IN SHORT MY QUESTION:

Can i get Eclipse to make a DLL file from functions.cpp before it attempts to build my code into a .exe file? At this stage my code is looking for an DLL file to IMPORT.

Upvotes: 0

Views: 2903

Answers (1)

JaredTS486
JaredTS486

Reputation: 436

I found out how to do this. It may not be the best option for this, however i was able to go to my project Properties-->C/C++ Build--->Settings--->Build Steps.

Screenshot of Build Steps tab with code.

This seems to work however I am now trying to find a way to set the command to use the source directory of the project instead of me having to use C:/eclipse/workplace etc.

Upvotes: 1

Related Questions