Discussion:
[asio-users] Trying to compile a .DLL file, any help is welcome
Jim Sager
2013-08-13 17:44:27 UTC
Permalink
Hello,

I am trying to compile a .DLL file.

Here is my syntax:


$g++ -c -DBUILDING_X blocking_udp_echo_client_dll.cpp -I /c/asio/include -I /c/boost

$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -Wl,--out-implib,  blocking_udp_echo_client_dll.a
Can't open .lib file:
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7startupERNS1_4dataEhh[asio::detail::winsock_init_base:
:startup(asio::detail::winsock_init_base::data&, unsigned char, unsigned char)]+
0x57): undefined reference to `***@8'
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7cleanupERNS1_4dataE[asio::detail::winsock_init_base::c
leanup(asio::detail::winsock_init_base::data&)]+0x1e): undefined reference to `W
***@0'
collect2: ld returned 1 exit status


I did some googling, and it said to add -lws2_32.  I tried this:
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -lws2_32 -Wl,--out-implib,  blocking_udp_echo_client_dll.a
Can't open .lib file:
collect2: ld returned 1 exit status
Jim Sager
2013-08-15 17:45:01 UTC
Permalink
Hello,

I'm trying to get ASIO working with Unreal Development Kit.  UDK doesn't allow C/C++ linking, but only linking to DLL.

Would the following be possible with a DLL?:
1) Send data to a server
2) Receive data from a server

I'm pretty sure it can send data to a server since that can be called in a function.
But receiving data from a server requires an async listening thread which I am not sure can be done with a DLL.


Any help would be appreciated.


,Jim




________________________________
From: Jim Sager <***@yahoo.com>
To: "asio-***@lists.sourceforge.net" <asio-***@lists.sourceforge.net>
Sent: Tuesday, August 13, 2013 1:44 PM
Subject: [asio-users] Trying to compile a .DLL file, any help is welcome



Hello,

I am trying to compile a .DLL file.

Here is my syntax:


$g++ -c -DBUILDING_X blocking_udp_echo_client_dll.cpp -I /c/asio/include -I /c/boost

$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -Wl,--out-implib,  blocking_udp_echo_client_dll.a
Can't open .lib file:
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7startupERNS1_4dataEhh[asio::detail::winsock_init_base:
:startup(asio::detail::winsock_init_base::data&, unsigned char, unsigned char)]+
0x57): undefined reference to
`***@8'
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7cleanupERNS1_4dataE[asio::detail::winsock_init_base::c
leanup(asio::detail::winsock_init_base::data&)]+0x1e): undefined reference to `W
***@0'
collect2: ld returned 1 exit status


I did some googling, and it said to add -lws2_32.  I tried this:
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -lws2_32 -Wl,--out-implib,  blocking_udp_echo_client_dll.a
Can't open .lib file:
collect2: ld returned 1 exit status

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
svante karlsson
2013-08-15 18:13:06 UTC
Permalink
I have no idea of Unreal development kit but as a generic question the
answer is:

Yes, you can start threads from within a dll. You can have a ASIO
threadpool if you like.

Or you can start a thread outside of the dll and call something like
"dll_perform_once" that handles a asio event and returns.
or something like "dll_perform" that does this forever - until its time to
exit.

(the dll_perform names where just an example.)

/svante
Post by Jim Sager
Hello,
I'm trying to get ASIO working with Unreal Development Kit. UDK doesn't
allow C/C++ linking, but only linking to DLL.
1) Send data to a server
2) Receive data from a server
I'm pretty sure it can send data to a server since that can be called in a function.
But receiving data from a server requires an async listening thread which
I am not sure can be done with a DLL.
Any help would be appreciated.
,Jim
------------------------------
*Sent:* Tuesday, August 13, 2013 1:44 PM
*Subject:* [asio-users] Trying to compile a .DLL file, any help is welcome
Hello,
I am trying to compile a .DLL file.
$g++ -c -DBUILDING_X blocking_udp_echo_client_dll.cpp -I /c/asio/include -I /c/boost
$ g++ -shared -o blocking_udp_echo_client_dll.dll
blocking_udp_echo_client_dll.
o -Wl,--out-implib, blocking_udp_echo_client_dll.a
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
:startup(asio::detail::winsock_init_base::data&, unsigned char, unsigned char)]+
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7cleanupERNS1_4dataE[asio::detail::winsock_init_base::c
leanup(asio::detail::winsock_init_base::data&)]+0x1e): undefined reference to `W
collect2: ld returned 1 exit status
$ g++ -shared -o blocking_udp_echo_client_dll.dll
blocking_udp_echo_client_dll.
o -lws2_32 -Wl,--out-implib, blocking_udp_echo_client_dll.a
collect2: ld returned 1 exit status
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Jim Sager
2013-08-15 19:15:16 UTC
Permalink
Question: Am I allowed to post a bounty question where I pay money to the person who answers?
I'm really stuck and need help to even begin coding.


I feel the person who helps me through this deserves to be paid since it would take you some work. If you don't want money, just take it and send it to a charity.  I can only pay one person though.


What I need is the following:

1) A function you send a string to, and it transfers that UDP string to 127.0.0.1 Port: Pick one (like 32739)

2) A listener that listens to incoming strings, and just stores them in a global variable(maybe char *) rewriting the value over for each incoming string. (I'll handle managing the strings myself)


3) A function that reads the last incoming string from the global variable.


4)Then tell me(step me through) how to compile this to a .dll with Mingw/MSYS for Windows.


To test your code you can run blocking_udp_echo_server.exe under asio/src/examples/echo


Thank you for reading. 



________________________________
From: svante karlsson <***@csi.se>
To: Jim Sager <***@yahoo.com>; Unname <asio-***@lists.sourceforge.net>
Sent: Thursday, August 15, 2013 2:13 PM
Subject: Re: [asio-users] Is a DLL even possible with ASIO?



I have no idea of Unreal development kit but as a generic question the answer is:
Yes, you can start threads from within a dll. You can have a ASIO threadpool if you like.


Or you can start a thread outside of the dll and call something like "dll_perform_once" that handles a asio event and returns.

or something like "dll_perform" that does this forever - until its time to exit.

(the dll_perform names where just an example.)

/svante










2013/8/15 Jim Sager <***@yahoo.com>

Hello,
Post by Jim Sager
I'm trying to get ASIO working with Unreal Development Kit.  UDK doesn't allow C/C++ linking, but only linking to DLL.
1) Send data to a server
2) Receive data from a server
I'm pretty sure it can send data to a server since that can be called in a function.
But receiving data from a server requires an async listening thread which I am not sure can be done with a DLL.
Any help would be appreciated.
,Jim
________________________________
Sent: Tuesday, August 13, 2013 1:44 PM
Subject: [asio-users] Trying to compile a .DLL file, any help is welcome
Hello,
I am trying to compile a .DLL file.
$g++ -c -DBUILDING_X blocking_udp_echo_client_dll.cpp -I /c/asio/include -I /c/boost
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -Wl,--out-implib,  blocking_udp_echo_client_dll.a
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
:startup(asio::detail::winsock_init_base::data&, unsigned char, unsigned char)]+
0x57): undefined reference to
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7cleanupERNS1_4dataE[asio::detail::winsock_init_base::c
leanup(asio::detail::winsock_init_base::data&)]+0x1e): undefined reference to `W
collect2: ld returned 1 exit status
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o  -lws2_32 -Wl,--out-implib,  blocking_udp_echo_client_dll.a
collect2: ld returned 1 exit
status
Post by Jim Sager
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Igor R
2013-08-15 19:09:06 UTC
Permalink
I'm trying to get ASIO working with Unreal Development Kit. UDK doesn't allow C/C++ linking, but only linking to DLL.
1) Send data to a server
2) Receive data from a server
I'm pretty sure it can send data to a server since that can be called in a function.
But receiving data from a server requires an async listening thread which I am not sure can be done with a DLL.
$g++ -c -DBUILDING_X blocking_udp_echo_client_dll.cpp -I /c/asio/include -I /c/boost
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o -Wl,--out-implib, blocking_udp_echo_client_dll.a
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
:startup(asio::detail::winsock_init_base::data&, unsigned char, unsigned char)]+
blocking_udp_echo_client_dll.o:blocking_udp_echo_client_dll.cpp:(.text$_ZN4asio6
detail17winsock_init_base7cleanupERNS1_4dataE[asio::detail::winsock_init_base::c
leanup(asio::detail::winsock_init_base::data&)]+0x1e): undefined reference to `W
collect2: ld returned 1 exit status
$ g++ -shared -o blocking_udp_echo_client_dll.dll blocking_udp_echo_client_dll.
o -lws2_32 -Wl,--out-implib, blocking_udp_echo_client_dll.a
collect2: ld returned 1 exit status
Yes, you definitely can use Asio in a dll.
The linker errors are because you have to link with Winsock (ws2_32),
but make sure libws2_32.a exists on the linker search path.
Jim Sager
2013-08-17 22:25:54 UTC
Permalink
Igor was able to give me syntax to build the dll, and it works with UDK.  I got it working after a few hours.  I am happy!

Background: I've built a game that uses ASIO and P2P before.  I had a thread that just fed the data into a large array.  Then when I got around to it, I read the new data that came in since I last checked.  It worked very well and I had multiplayer.

My question is: Can you do multithreaded code in a .dll?  If so, what is the syntax?

I would like a thread that does this:
It listens on a port for incoming data, and then rewrites over a global variable the data that came in.  If I had this listener, I could expand it to fill up an array of strings, and then when I check for all the updates, I could read all the incoming data on a different function.

Here is what my code looks like now that works sending out a packet:
#include <stdio.h>
#include "example_dll.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "asio.hpp"

using asio::ip::udp;

enum { max_length = 1024 };

__declspec(dllexport) void networksend(int x)
{  
    asio::io_service io_service;
    udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
    udp::resolver resolver(io_service);
    udp::resolver::query query(udp::v4(), "127.0.0.1", "25789");
   udp::resolver::iterator iterator = resolver.resolve(query);
    size_t request_length = strlen("hello4");//just sends hello4 over the network
    s.send_to(asio::buffer("hello4", request_length), *iterator);
   
}
Igor R
2013-08-18 07:26:26 UTC
Permalink
My question is: Can you do multithreaded code in a .dll? If so, what is the
syntax?
Sure, you can do this just like in a standalone executable:

http://www.boost.org/doc/libs/1_54_0/doc/html/thread/thread_management.html#thread.thread_management.tutorial

void workerFunction(Arg1 a1, Arg2 a2)
{
// do anything here
// when the function exits, the thread ends
}

void someEntrypoint()
{
boost::thread t(&workerFunction, param1, param2);
t.detach();
}
It listens on a port for incoming data, and then rewrites over a global
variable the data that came in. If I had this listener, I could expand it
to fill up an array of strings, and then when I check for all the updates, I
could read all the incoming data on a different function.
Please note that with Asio you don't have to receive data in a thread.
Instead, you can take an advantage of the asynchronous facilities --
that's what Asio is for.
See async tcp and udp echo server examples:
http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/example/cpp03/echo/async_tcp_echo_server.cpp
http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/example/cpp03/echo/async_udp_echo_server.cpp



HTH,

Igor'.

Continue reading on narkive:
Loading...