Symbol Definitionsproblem (WIN32_DLL)
-
Hallo!
Habe im Internet folgenden Artikel gefunden
8. Using DLLs
Currently it's possible to build DLLs from the OMNeT++ libraries and link a simulation program which uses them. However, because of some obscure technical problems associated with loading the DLLs, the resulting simulation program will not run :-( (Well in case you're interested why: A DLL, while initializing, cannot write outside its address space. OMNeT++, however, would rely on this mechanism to build global registration lists ("modules", "networks", etc). Each item in a registration list is an object whose constructor would add the object to the global list (an object outside the DLL), and it seems like constructors of global objects run as part of the DLL initialisation code (DLLMain())). To build the DLLs anyway, set the desired library suffix to ".dll" in configuser.vc: LIB_SUFFIX=.dll After re-building OMNeT++, the DLLs should appear in the lib/ directory, together with the respective import libraries which have the .ilib suffix. (You may want to rename them manually to .lib.) There's one trick when using the DLLs: when you compile your model sources, you must have the **WIN32_DLL** symbol #defined! It is best to pass them to the compiler **from your makefile** (or if you use the IDE, add it to Settings --> C/C++ --> Preprocessor --> Preprocessor definitions). If you fail to do so, you'll get undefined linker symbols!
Wie kann ich das hinzufügen? Welche Zeile muss ich da in das Makefile einfügen und welchen Wert bekommt dieses Symbol?
Lg THE_ONE
Ps.: Da gehts darum wie man für OMNet++ eine DLL kompilieren kann. Bekomme nämlich zig LNK Errors
, und bin über Google auf oben zitierten test gestoßen. Ich hoffe das es mir helfen wird. Verwende Visual Studio Pro 2008
-
Hallo,
das Symbol benötigt keinen Wert, es soll lediglich definiert werden. Da du mit Visual Studio Pro 2008 arbeitest, würde ich diesen Weg:
add it to
Settings --> C/C++ --> Preprocessor --> Preprocessor definitionsvorschlagen bzw.:
http://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx
MfG,
Probe-Nutzer
-
Hallo!
Und danke für deine Antwort!
Ich verwende nur den C++ Compiler und nicht das Studio selbst. Würde daher gerne den anderen Weg gehen! Könntest du mir erklären wie man das mit dem Makefile hinbekommt,was muss ich dort einfügen??
Kann ich einfach ins Makefile schreiben: #define WIN32_DLL ??
Lg THE_ONE
-
THE_ONE schrieb:
#define WIN32_DLL ??
#defines funktionieren leider nur im C++-Code selber. wenn du aus einer makefile den Compiler direkt aufrufst musst du ihm die definierten Symbole beim aufruf als Kommandozeilenparameter mitgeben. versuchs mal mit -DWIN32_DLL als zusätzlichem Parameter
-
Hallo!
Danke, hab jetzt nochmal gründlich den Oment Ordner nach dem string WIN32_DLL durchsucht und bin auf folgendes gestoßen
../onet++/doc/Readme_MSVC.txt
:
8. Using DLLs
It is possible to load a simulation model from a DLL. Suppose you have a DLL called queueing.dll, which contains all modules from the "queueing" sample simulation. Then you can load it into an appropriate sim.exe with the following command-line: sim.exe -l queueing This will cause sim.exe to load queueing.dll on startup, so you may now use queueing simple modules in your simulations. The .dll filename extension is added automatically (this allows for some degree of platform independence -- on Unix, .so is added.) If you don't want to add the -l command-line option every time, then adding [General] load-libs = "queueing" to omnetpp.ini will also do the job. Multiple DLLs can also be loaded (use multiple -l options, or load-libs="lib1 lib2 lib3 ..." in omnetpp.ini). To build the DLL: Create a file named makefrag.vc in the directory of the simple module sources with the following content: \# makefrag.vc -- settings for creating a dll EXPORTLIB = sim.lib TARGET= $(TARGET:.exe=.dll) LDFLAGS= $(LDFLAGS) /dll OMNETPP_LIBS= $(EXPORTLIB) COPTS= $(COPTS) **/DWIN32_DLL** NEDCOPTS= $(NEDCOPTS) **/DWIN32_DLL** Adjust the EXPORTLIB= setting at the top: it should point to the export library of the program you'll load the DLL into. (An export library is automatically generated every time you build az OMNeT++ simulation executable, with name <programname>.lib). The rest of the settings don't need to be changed. Then generate a Makefile.vc with the appropriate opp_nmakemake command (makefrag.vc be inserted into the generated file.) Then if you just normally build (nmake -f Makefile.vc), you should get a DLL as a result. Note: the resulting DLL can only be loaded into the sim.exe whose export library was used for building the DLL.
Hier sieht man auch wie WIN32_DLL dem Compiler übergeben wird. (Zusatzinfo zu WIN32 DLLs)
Leider hat sich mein eigentliches Problem dadurch noch nicht gelöst. Habe noch immer zig LNK Fehler des Typs:
C:\OMNeT++\samples\Test01>opp_nmakemake -f -s Creating Makefile.vc in C:/OMNeT++/samples/Test01... Makefile.vc created. Please type `nmake -f Makefile.vc depend' NOW to add dependencies! C:\OMNeT++\samples\Test01>nmake -f Makefile.vc depend Microsoft (R) Program Maintenance Utility, Version 9.00.21022.08 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. call C:/OMNeT++/bin/opp_makedep -Y --objsuffix .obj --objdirtree -f Makefile.vc -- *.cpp if not ""=="" for %i in ( ) do cd %i && echo [depend in %i] && nmake /nologo /f Makefile.vc depend && cd .. || exit /b 1 C:\OMNeT++\samples\Test01>nmake -f Makefile.vc Microsoft (R) Program Maintenance Utility, Version 9.00.21022.08 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. link.exe /nologo /dll /subsystem:console /opt:noref /dll tictoc1_n.obj txc1.obj /out:Test 01.dll tictoc1_n.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __cdecl cRuntimeError::cRuntimeError(char const *,...)" (__imp_??0cRuntimeError@@QAA@PBDZZ) " in Funktion ""class cModuleType * __cdecl _getModuleType(char const *)" (?_getModuleType@@YAPAVcMo duleType@@PBD@Z)". ... ... ...
-> Kennt jemand solche fehler und weiß vielleicht was man dagegen machen kann??
-
Hallo zu der .dll müsste es auch eine .lib geben.
Die musst du dann dem Linker als zusätzlichen Input angeben.
Wie das im make geht weiß ich nicht. Kannst aber immer ein Projekt in der IDE öffnen und dann die Linker kommandozeile abkucken.
-
steht in der .LIB und der .DLL nicht dasselbe drinnen, nur halt das das eine statisch ist und das andere dynamisch?? D.h. das eine wird zur Compile Zeit gelinkt das andere zur Laufzeit. Brauche ich für die DLL überhaupt die LIB?
Gibt es virlleicht irgendwo Infos zu LIBs und DLLs und wie diese zusammenhängen (zusammenspielen)?
Mich treiben diese Linkerfehler noch in den Wahnsinn
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ 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.