SOLVED - Linkerfehler bei DLL



  • Hallo.

    Ich habe einen Code erstellt, den ich jetzt in eine DLL exportieren möchte um das in C# zu nutzen. Ich habe das schon gemacht und habe eigentlich versucht, alles exakt gleich zu gestalten. Einziger Unterschied: Meine funktionierendes DLL Projekt wurde ursprünglich in VS2013 erstellt, jetzt bin ich auf 2015 umgestiegen.

    Wenn ich auf "Build" klicke, erhalte ich zwei Fehlermeldungen:
    Severity Code Description Project File Line
    Error LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) DomainKernel C:\...Pfad gekürzt...\MSVCRTD.lib(exe_main.obj) 1

    Severity Code Description Project File Line
    Error LNK1120 1 unresolved externals DomainKernel C:\...Pfad gekürzt...\DomainKernel.exe 1

    Ich habe (hoffe ich) alle Einstellungen aus dem funktionierenden Projekt übernommen. Einzig wenn ich im Solution Explorer auf Properties klicke und dann Common properties >> Debug source files wähle, sieht es anders aus. Bei dem alten, funktionierenden Projekt sind lediglich zwei Einträge auf Dateien im VS12 Ordner vorhanden. Bei dem neuen Projekt ist es schon deutlich umfangreicher.

    Mir ist schon klar, dass ich die Main-Funktion nicht habe - aber die brauche ich in einer DLL ja auch nicht. Ich denke, VS2015 versteht nicht - oder besser, ich habe es ihm nicht mitgeteilt, dass ich eine DLL exportieren möchte. Beim Erstellen des Projekts habe ich VC++ >> Empty project gewählt, da ich die ganzen automatisch generierten Dateien nicht haben wollte.

    Anbei der Code, der wahrscheinlich gar nicht so wichtig ist, denn ich denke der Fehler liegt wo anders:

    Code der cpp Datei:

    #pragma region Definitions
    #define _CRT_SECURE_NO_WARNINGS
    #pragma endregion Definitions
    
    #pragma region Includings
    #ifndef STDIO_H
    	#define STDIO_H
    	#include <stdio.h>
    #endif
    
    #ifndef STDLIB_H
    	#define STDLIB_H
    	#include <stdlib.h>
    #endif
    
    #ifndef STRING_H
    	#define STRING_H
    	#include <string.h>
    #endif
    
    #ifndef MATH_H
    	#define MATH_H
    	#include <math.h>
    #endif
    
    #ifndef SYS_STRUCT_H
    	#define SYS_STRUCT_H
    	#include <sys/stat.h>
    #endif
    
    #ifndef OMP_H
    	#define OMP_H
    	#include <omp.h>
    #endif
    
    #ifndef WINDOWS_H
    	#define WINDOWS_H
    	#include <Windows.h>
    #endif
    
    #ifndef IO_H
    	#define IO_H
    	#include <io.h>
    #endif
    
    #ifndef FCNTL_H
    	#define FCNTL_H
    	#include <fcntl.h>
    #endif
    
    #ifndef ENUMERATIONS_H
    	#include "Enumerations.h"
    #endif
    
    #ifndef MESHSTRUCT_3D
    	#include "MeshStruct3D.h"
    #endif
    
    #ifndef STRUCTDOMAIN_H
    	#include "StructDomain.h"
    #endif
    
    #ifndef DOMAINHANDLE_H
    	#include "DomainHandle.h"
    #endif
    #pragma endregion Includings
    
    static TDomain** ppDomain = NULL;
    unsigned int npDomain = 0;
    

    Code der Headerdatei:

    #define DOMAINHANDLE_H
    
    void InitializeDomain(TDomain* D);
    void SetDomainStacks(TDomain* D);
    extern "C" __declspec(dllexport) void ChangeDomainName(TDomain* D, char* DomainName);
    extern "C" __declspec(dllexport) TDomain* AddDomain();
    extern "C" __declspec(dllexport) unsigned int DomainStack_Count();
    extern "C" __declspec(dllexport) TMesh** AllocateMeshStack(TDomain* D, unsigned long npMesh);
    extern "C" __declspec(dllexport) TMesh** ReallocateMeshStack(TDomain* D, unsigned long npMesh);
    extern "C" __declspec(dllexport) void SetPressureGradientType(TDomain* D, unsigned int Type);
    extern "C" __declspec(dllexport) void SetPressureVelocityCouplingType(TDomain* D, unsigned int Type);
    
    extern TDomain** ppDomain;
    extern unsigned int npDomain;
    
    extern "C" __declspec(dllexport) unsigned int DomainStack_Count() { return npDomain; }
    
    extern "C" __declspec(dllexport) TDomain* AddDomain() {
    
    	TDomain* NewDomain = NULL;
    
    	NewDomain = (TDomain*)malloc(sizeof(TDomain));
    	InitializeDomain(NewDomain);
    
    	if (npDomain == 0) {
    		ppDomain = (TDomain**)malloc(sizeof(TDomain*));
    	}else {
    		ppDomain = (TDomain**)realloc(ppDomain, (npDomain + 1) * sizeof(TDomain*));
    	}
    
    	ppDomain[npDomain] = NewDomain;
    
    	return ppDomain[npDomain++];
    }
    
    extern "C" __declspec(dllexport) void ChangeDomainName(TDomain* D, char* DomainName) {
    	if (D->DomainName != NULL) { free(D->DomainName); }
    
    	D->DomainName = (char*)malloc(strlen(DomainName) * sizeof(char));
    	strcpy(D->DomainName, DomainName);
    }
    
    extern "C" __declspec(dllexport) TMesh** AllocateMeshStack(TDomain* D, unsigned long npMesh) {
    	if (D->ppMesh != NULL) { free(D->ppMesh); D->npMesh = 0; }
    
    	D->ppMesh = (TMesh**)malloc(npMesh * sizeof(TMesh*));
    	D->npMesh = npMesh;
    
    	SetDomainStacks(D);
    
    	return D->ppMesh;
    }
    
    extern "C" __declspec(dllexport) TMesh** ReallocateMeshStack(TDomain* D, unsigned long npMesh) {
    	if (D->ppMesh != NULL) { free(D->ppMesh); D->npMesh = 0; }
    
    	D->ppMesh = (TMesh**)malloc(npMesh * sizeof(TMesh*));
    	D->npMesh = npMesh;
    
    	SetDomainStacks(D);
    
    	return D->ppMesh;
    }
    
    extern "C" __declspec(dllexport) void SetPressureGradientType(TDomain* D, unsigned int Type) {
    	switch (Type) {
    	case 0: /*Gauss node*/
    		D->PressureGradientType = GAUSS_NODE;
    		break;
    	case 1: /*Gauss cell*/
    		D->PressureGradientType = GAUSS_CELL;
    		break;
    	default: /*Least square*/
    		D->PressureGradientType = LEAST_SQARE;
    		break;
    	}
    }
    
    extern "C" __declspec(dllexport) void SetPressureVelocityCouplingType(TDomain* D, unsigned int Type) {
    	switch (Type) {
    	default:
    		D->PressureVelocityCoupling = SIMPLE;
    		break;
    	}
    }
    
    void SetDomainStacks(TDomain* D) {
    	TMesh* M = NULL;
    	unsigned int MeshCounter = 0;
    	unsigned long i = 0, j = 0, k = 0, l = 0, m = 0;
    
    	D->npCell = 0; D->npFace = 0; D->npExternalCell = 0; 
    
    	if (D->ppCell == NULL) { free(D->ppCell); }
    	if (D->ppFace == NULL) { free(D->ppFace); }
    	if (D->ppExternalCell == NULL) { free(D->ppExternalCell); }
    
    	for (MeshCounter = 0; MeshCounter < D->npMesh; MeshCounter++) {
    		M = D->ppMesh[MeshCounter];
    
    		D->npCell += M->nCell;
    		D->npFace += M->nFace;
    		D->npExternalCell += M->nExternalCell;
    	}
    
    	D->ppCell = (TCell**)malloc(D->npCell * sizeof(TCell*));
    	D->ppFace = (TFace**)malloc(D->npFace * sizeof(TFace*));
    	D->ppExternalCell = (TCell**)malloc(D->npExternalCell * sizeof(TCell*));
    
    	if (D->ppCell == NULL || D->ppFace == NULL || D->ppExternalCell == NULL) {
    		printf("ERROR - Unable to allocate memory for domain contents!");
    		exit;
    	}
    
    	D->npCell = 0;
    	D->npFace = 0;
    	D->npExternalCell = 0;
    
    	for (MeshCounter = 0; MeshCounter < D->npMesh; MeshCounter++) {
    		M = D->ppMesh[MeshCounter];
    
    		for (i = 0; i < M->nCell; i++) {D->ppCell[D->npCell++] = &M->pCell[i];}
    		for (i = 0; i < M->nFace; i++) { D->ppFace[D->npFace++] = &M->pFace[i]; }
    		for (i = 0; i < M->nExternalCell; i++) { D->ppExternalCell[D->npExternalCell++] = M->ppExternalCell[i]; }
    	}
    }
    
    void InitializeDomain(TDomain* D) {
    	D->DomainName = NULL;
    
    	D->ppMesh = NULL;
    	D->npMesh = 0;
    
    	D->ppCell = NULL;
    	D->npCell = 0;
    
    	D->ppExternalCell = NULL;
    	D->npExternalCell = 0;
    
    	D->ppFace = NULL;
    	D->npFace = 0;
    
    	D->ppExternalFace = NULL;
    	D->npExternalFace = 0;
    
    	D->PressureGradientType = LEAST_SQARE;
    	D->PressureVelocityCoupling = SIMPLE;
    
    	D->Solver.SolverType = BiCGStab;
    
    	D->Solver.MinimumIteration = 0;
    	D->Solver.MaximumIteration = 0;
    
    	D->Solver.ResidualType = RESMAX;
    	D->Solver.ResidualValue = .0;
    }
    


  • Sorry, hatte vergessen, den Configuration Type von Application (.exe) auf Dynamic Link Library (.dll) umzustellen. Jetzt läuft es.



  • Dieser Thread wurde von Moderator/in Arcoth aus dem Forum C++ (alle ISO-Standards) in das Forum Compiler- und IDE-Forum verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


Anmelden zum Antworten