Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including g++ dll in VC++

Status
Not open for further replies.

dn8

Programmer
Jul 16, 2010
1
DK
Hi,

I am new to programming with visual studio and now I have the problem using fortran routines in vc++.
My workaround is to compile a dll using gfortran and g++ in a MinGW setup and use them in Visual Studio.
The files are mydll.cc

#include <iostream>

extern "C" {
void fhello_(void);
}

void
hello()
{
std::cout << "DLL wrapper "<< std::endl;
fhello_();
}

and myfdll.f:

SUBROUTINE FHELLO
WRITE (*,100)
STOP
100 FORMAT ('HELLO F WORLD!')
END

Compiling a dll with
g++ -shared -o mydll.dll mydll.o myfdll.o -lgfortran -Wl,export-all-symbols -Wl,outimplib
works well and the dll could be used in a c++ program

#include "mydll.h"
int main()
{
hello();
return 0;
}

calling this dll with
g++ -o main.exe main.o mydll.dll

with the header

#ifndef MYDLL_H
#define MYDLL_H
void hello();
#endif

works well.

When I include these files in a VC++ Project, include the produced lib file, e.g. produced with
dlltool --def foo.def -dllname mydll.dll --output-lib mydll.lib

Compiling this produces the linker error:
main.obj : error LNK2019: unresolved external symbol "void __cdecl hello(void)" (?hello@@YAXXZ) referenced in function _main

I look around in the web but there I did not find anything that works for my problem.

Can someone help me with this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top