Hi Im trying to create a DLL from a library called Enet:
http://enet.bespin.org/
I got the source and compiled it into a static library,
then I created a new project:
// dll.h
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT int CALLBACK mymagicfunction(void);
#include <windows.h>
#include "dll.h"
EXPORT int CALLBACK mymagicfunction(void)
{
enet_initialize();
}
I told the IDE to use libenet.a as a linker. (the static library that I compiled)
the error message was:
ld.exe cannot find -lEnet
Turn on Compiler Logging and post the part of "Build Log" that contains the "ld.exe cannot find -lEnet" error and the 3 or 4 command lines right before it.
Steps to turn on Compiler Logging:
"Settings" -> "compiler debugger"
Change "Compiler Settings" to "Other Settings"
Set "Compiler Logging" to "Full Command Line"
thanks for helping:
Quote
Project : DLL Sample
Compiler : GNU GCC Compiler (called directly)
Directory : C:\download\enet-1.0\enet-1.0\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe -shared -Wl,--out-implib=libEnet.a -Wl,--dll -LC:\Dev-Cpp\lib .objs\main.o -o Enet.dll -lEnet
C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lEnet
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings
Where is Enet related to the project cbp file?
You need to add it to the search path in CB.
"Project" -> "Build Options"
Change to "Search Diretories"
Add the folder holding Enet library to linker tab.
Tim S
that worked THANKS
but now it is saying 'undefined reference to enet_initialize()'
I know for a fact that function/command is in the Enet source code.
Is just including the static library enough?
Quote from: slenkar on May 18, 2007, 10:39:57 PM
that worked THANKS
but now it is saying 'undefined reference to enet_initialize()'
I know for a fact that function/command is in the Enet source code.
Is just including the static library enough?
This is a little to complex for me to answer, I am a newbie to c++ and have forgotten most of my C language knowledge.
But, I think including static library should be enough.
I am downloading 1.0 version of enet to see if I can see something.
Tim S
Are you building the debug or the release version of the projects?
The release compiled for me, but the debug version did not.
Tim S
The below code worked for me in release, but not in debug.
#include <windows.h>
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#include "enet/enet.h"
int DLL_EXPORT CALLBACK mymagicfunction(void);
int DLL_EXPORT CALLBACK mymagicfunction(void)
{
enet_initialize();
}
As two files below. Works in release not in debug. A lot of the time debug needs windows libraries not on my system to work, it could work on yours.
Remember to define BUILD_DLL in the project building the DLL.
Tim S
// dll.h
#ifndef DLL_H_INCLUDED
#define DLL_H_INCLUDED
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
int DLL_EXPORT CALLBACK mymagicfunction(void);
#ifdef __cplusplus
}
#endif
#endif // DLL_H_INCLUDED
#include <windows.h>
#include "dll.h"
#include "enet/enet.h"
int DLL_EXPORT CALLBACK mymagicfunction(void)
{
enet_initialize();
}
thanks
how do you put it in release mode?
and which files do I add to the project?
Quote from: slenkar on May 19, 2007, 12:07:20 AM
thanks
how do you put it in release mode?
and which files do I add to the project?
On the compiler toolbar, change "Build Target" to "Release"
Note: I used the GUI to start the DLL Project.
File -> New -> Project -> "Dynamic Link Library"
It defaults to two targets "Debug" and "Release"
I edited the single file main.cpp like my sample above.
Note, if I leave out the include of "enet/enet.h" I get an error like yours. But, I needed to the other changes to get it to work.
Tim S
I can only seem to get
default
or
all
as choices for the build target
Did you build the Enet static library as debug or as release?
Debug in minGW GCC normally means options "-g" and "-D_DEBUG" are used.
Release in minGW GCC normally means option "-DNDEBUG" is used; sometimes optimize options like "-O2" are only used with release.
Note, I just found what looks like bad setting on building the debug version of Enet static library. Will retry it again.
Did you build Enet static library using Code::Blocks?
Did you build Enet static library using minGW GCC?
Tim S
Found out that the Release build was failing also, Code::Blocks just was not displaying the error in the message window.
Will post more if I get it to work.
Tim S
I think I got it to work.
You need to add libraries
enet, wsock32, winmm, ws2_32
Uploaded project to http://www.savefile.com/files/733788
The rest of my CodeBlocks stuff is at http://www.savefile.com/projects/1039215
File layout top is the folder that contains enet.dsp; only some files shown, but it should be enough to confirm where to extract to.
/top/enet.dsp
/top/enet.cbp
/top/enet.workspace
/top/testdll/testdll.cbp
Tim S
I built the library with codeblocks,
not sure if I used debug or not,
I downloaded the archive program 7-zip and it said 7z was an unsupported format (!!!!!)
If I go off the beaten track with computers they dont work for me, for some reason.
thanks for the help so far,
I remember trying to download the ws2_32 library but I couldnt find it on google.
Quote from: slenkar on May 19, 2007, 06:42:11 PM
I built the library with codeblocks,
not sure if I used debug or not,
I downloaded the archive program 7-zip and it said 7z was an unsupported format (!!!!!)
If I go off the beaten track with computers they dont work for me, for some reason.
thanks for the help so far,
I remember trying to download the ws2_32 library but I couldnt find it on google.
http://www.7-zip.org/ has 7Zip on it.
You don't need to download ws2_32 just add it to the "Link libraries" under "Linker Settings"
I will try to upload again, the 7z file seems to be damaged; I can't seem to upload Binary files right now.
ISP or http://www.savefile.com issues most likely.
I put the files on my project shown below to view them.
http://csharp-6809.svn.sourceforge.net/viewvc/csharp-6809/codeblocks/enet-1.0.7z?view=log
http://csharp-6809.svn.sourceforge.net/viewvc/csharp-6809/codeblocks/enet-1.0/
Tim S
yeh I think it was damaged,
The CBP file downloaded as an XML
Ill try renaming it.
Ok I renamed it
then I put the files in the right places and double-clicked the enet.workspace
and tried to build the project but it says:
'nothing to be done'
and
if I try to run it, it says,
'needs host application'
I tried to 'rebuild' and it created a static library
libenet.a
OK I tried compiling the DLL project and added the directories and it worked, now to test if the DLL exports commands correctly!
now its acting strange, I change the Main.cpp file and press build, but it doesnt detect any errors, even when I make errors on purpose
Code::Blocks does not always show errors in the build message window.
Look for then in the build log window.
I forget why this happens, I thought it was fixed till working on your issue.
Tim S