Author Topic: Trying to create a DLL from Enet source code  (Read 10050 times)

Offline slenkar

  • Single posting newcomer
  • *
  • Posts: 7
Trying to create a DLL from Enet source code
« on: May 18, 2007, 03:09:08 pm »
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:



Code: [Select]
// dll.h
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif

EXPORT int CALLBACK mymagicfunction(void);

Code: [Select]
#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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #1 on: May 18, 2007, 06:54:24 pm »
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"
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline slenkar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Trying to create a DLL from Enet source code
« Reply #2 on: May 18, 2007, 08:55:43 pm »
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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #3 on: May 18, 2007, 09:44:44 pm »
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
« Last Edit: May 18, 2007, 09:50:18 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline slenkar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Trying to create a DLL from Enet source code
« Reply #4 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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #5 on: May 18, 2007, 10:49:16 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
 
« Last Edit: May 18, 2007, 10:51:15 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #6 on: May 18, 2007, 11:09:40 pm »
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
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #7 on: May 18, 2007, 11:23:52 pm »
The below code worked for me in release, but not in debug.

Code: [Select]
#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();
}
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #8 on: May 18, 2007, 11:30:37 pm »
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

Code: [Select]
// 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


Code: [Select]
#include <windows.h>
#include "dll.h"
#include "enet/enet.h"

int DLL_EXPORT CALLBACK mymagicfunction(void)
{
       enet_initialize();
}

« Last Edit: May 18, 2007, 11:47:12 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline slenkar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Trying to create a DLL from Enet source code
« Reply #9 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?
« Last Edit: May 19, 2007, 02:16:52 am by slenkar »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #10 on: May 19, 2007, 03:05:04 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
« Last Edit: May 19, 2007, 03:11:39 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline slenkar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Trying to create a DLL from Enet source code
« Reply #11 on: May 19, 2007, 03:32:26 am »
I can only seem to get

default
or
all

as choices for the build target

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #12 on: May 19, 2007, 03:43:27 am »
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
« Last Edit: May 19, 2007, 04:05:00 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #13 on: May 19, 2007, 05:07:18 am »
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
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6613
    • My Best Post
Re: Trying to create a DLL from Enet source code
« Reply #14 on: May 19, 2007, 05:27:06 am »
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
« Last Edit: May 19, 2007, 05:35:30 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org