Tengo un proyecto en codeblocks en Linux que se compila y ejecuta perfectamente, sin embargo el mismo proyecto en windows no hay manera de que compile, me saltan muchos errores la mayoría del tipo: undefined reference to `printf'. Al ser estandar no deberia haber problema, no?
El codigo lo he sacado de: tws-c-api.cvs.sourceforge.net/viewvc/tws-c-api/tws_client_api/
De los 4 archivos la unica modificación que le he hecho es al archivo example.c, dejandolo así:
Código C++:
Ver original#include "twsapi.h"
#ifdef unix
//#include <pthread.h>
#include <sys/select.h>
#include <netdb.h>
#include <fcntl.h>
#else
#include <process.h>
#include <winsock2.h>
#include <WS2tcpip.h> /* for ipv6 DNS lookups if needed */
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>
static void tws_thread_status(int arg)
{
/* the real reason for having this func
* is so that array_of_threads[NAME_OF_THIS_ONE] can be set to
* pthread_self() on startup and 0 on termination, so that
* the top level thread can cancel one or all if it wants to
*/
printf("tws reader thread %s\n", arg
? "terminated" : "started"); }
/* User is responsible for implementing this function
* name is a null terminated string
* addr is where the address should be copied on success
* addr_len contains length of addr buffer and
* may be decreased on return to caller
* function returns -1 on failure, 0 on success
*/
static int resolve_name(const void *name, void *addr, long *addr_len)
{
int error = -1;
#if 1
struct hostent *h;
if(*addr_len < 4)
goto out;
h = gethostbyname((char *) name); /* does not support ipv6 either, though the API does */
if(!h)
goto out;
memcpy(addr
, h
->h_addr_list
[0], 4); *addr_len = 4;
error = 0;
#else
struct addrinfo *ai = 0, hints;
if(*addr_len < 4)
goto out;
memset((void *) &hints
, 0, sizeof hints
); hints.ai_family = PF_INET; /* first attempt ipv4 resolution */
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo((char *) name, 0, &hints, &ai);
if(!error && ai && ai->ai_family == PF_INET) {
struct sockaddr_in a4;
memcpy((void *) &a4
, &ai
->ai_addr
[0], sizeof a4
); memcpy(addr
, &a4.
sin_addr, 4); *addr_len = 4;
error = 0;
} else
error = -1;
if(ai)
freeaddrinfo(ai);
if(!error)
goto out;
/* try to get an ipv6 address */
if(*addr_len < 16) {
error = -1;
goto out;
}
ai = 0;
hints.ai_family = PF_INET6;
error = getaddrinfo((char *) name, 0, &hints, &ai);
if(!error && ai && ai->ai_family == PF_INET6) {
struct sockaddr_in6 a6;
memcpy((void *) &a6
, &ai
->ai_addr
[0], sizeof a6
); memcpy(addr
, &a6.
sin6_addr, 16); *addr_len = 16;
error = 0;
} else
error = -1;
if(ai)
freeaddrinfo(ai);
#endif
out:
return error;
}
int main(int argc, char *argv[])
{
int err;
void *ti;
/* 'no_thread' here could also mean that an externally spawned thread
* that we did not create will handle IO from TWS, somehow we may happen
* to run in the context of that thread
*/
ti = tws_create( TWS_NO_THREAD , (void *) 0x12345, tws_thread_status);
err = tws_connect(ti, 0 , 7496, 1, resolve_name);
if(err) {
printf("tws connect returned %d\n", err
); exit(1); }
tr_contract_t c;
c.c_symbol = "DELL";
c.c_sectype = "STK";
c.c_expiry = "";
c.c_right = "";
c.c_multiplier = "";
c.c_exchange = "SMART";
c.c_primary_exch = "";
c.c_currency = "USD";
c.c_local_symbol = "";
tws_request_realtime_bars(ti, 4, &c, 5, "TRADES", 0);
while(0 == tws_event_process(ti));
tws_destroy(ti);
return 0;
}