Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Multiplataforma

Estas en el tema de Multiplataforma en el foro de C/C++ en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 08/05/2009, 13:22
 
Fecha de Ingreso: abril-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Multiplataforma

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
  1. #include "twsapi.h"
  2.  
  3. #ifdef unix
  4. //#include <pthread.h>
  5. #include <sys/select.h>
  6. #include <netdb.h>
  7. #include <fcntl.h>
  8. #else
  9. #include <process.h>
  10. #include <winsock2.h>
  11. #include <WS2tcpip.h> /* for ipv6 DNS lookups if needed */
  12. #endif
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <float.h>
  18. #include <math.h>
  19.  
  20. static void tws_thread_status(int arg)
  21. {
  22.     /* the real reason for having this func
  23.      * is so that array_of_threads[NAME_OF_THIS_ONE] can be set to
  24.      * pthread_self() on startup and 0 on termination, so that
  25.      * the top level thread can cancel one or all if it wants to
  26.      */
  27.     printf("tws reader thread %s\n", arg ? "terminated" : "started");
  28. }
  29.  
  30. /* User is responsible for implementing this function
  31.  * name is a null terminated string
  32.  * addr is where the address should be copied on success
  33.  * addr_len contains length of addr buffer and
  34.  * may be decreased on return to caller
  35.  * function returns -1 on failure, 0 on success
  36.  */
  37. static int resolve_name(const void *name, void *addr, long *addr_len)
  38. {
  39.     int error = -1;
  40. #if 1
  41.     struct hostent *h;
  42.  
  43.     if(*addr_len < 4)
  44.         goto out;
  45.  
  46.     h = gethostbyname((char *) name); /* does not support ipv6 either, though the API does */
  47.     if(!h)
  48.         goto out;
  49.  
  50.     memcpy(addr, h->h_addr_list[0], 4);
  51.     *addr_len = 4;
  52.     error = 0;
  53. #else
  54.     struct addrinfo *ai = 0, hints;
  55.  
  56.     if(*addr_len < 4)
  57.         goto out;
  58.  
  59.     memset((void *) &hints, 0, sizeof hints);
  60.     hints.ai_family = PF_INET; /* first attempt ipv4 resolution */
  61.     hints.ai_socktype = SOCK_STREAM;
  62.     error = getaddrinfo((char *) name, 0, &hints, &ai);
  63.     if(!error && ai && ai->ai_family == PF_INET) {
  64.         struct sockaddr_in a4;
  65.  
  66.         memcpy((void *) &a4, &ai->ai_addr[0], sizeof a4);
  67.         memcpy(addr, &a4.sin_addr, 4);
  68.         *addr_len = 4;
  69.         error = 0;
  70.     } else
  71.         error = -1;
  72.  
  73.     if(ai)
  74.         freeaddrinfo(ai);
  75.  
  76.     if(!error)
  77.         goto out;
  78.  
  79.     /* try to get an ipv6 address */
  80.     if(*addr_len < 16) {
  81.         error = -1;
  82.         goto out;
  83.     }
  84.  
  85.     ai = 0;
  86.     hints.ai_family = PF_INET6;
  87.     error = getaddrinfo((char *) name, 0, &hints, &ai);
  88.  
  89.     if(!error && ai && ai->ai_family == PF_INET6) {
  90.         struct sockaddr_in6 a6;
  91.  
  92.         memcpy((void *) &a6, &ai->ai_addr[0], sizeof a6);
  93.         memcpy(addr, &a6.sin6_addr, 16);
  94.         *addr_len = 16;
  95.         error = 0;
  96.     } else
  97.         error = -1;
  98.  
  99.     if(ai)
  100.         freeaddrinfo(ai);
  101. #endif
  102. out:
  103.     return error;
  104. }
  105.  
  106. int main(int argc, char *argv[])
  107. {
  108.     int err;
  109.     void *ti;
  110.  
  111.  
  112.     /* 'no_thread' here could also mean that an externally spawned thread
  113.      * that we did not create will handle IO from TWS, somehow we may happen
  114.      * to run in the context of that thread
  115.      */
  116.     ti = tws_create( TWS_NO_THREAD , (void *) 0x12345, tws_thread_status);
  117.     err = tws_connect(ti, 0 , 7496, 1, resolve_name);
  118.     if(err) {
  119.         printf("tws connect returned %d\n", err); exit(1);
  120.     }
  121.  
  122.  
  123.     tr_contract_t c;
  124.     memset(&c, 0, sizeof c);
  125.     c.c_symbol = "DELL";
  126.     c.c_sectype = "STK";
  127.     c.c_expiry = "";
  128.     c.c_right = "";
  129.     c.c_multiplier = "";
  130.     c.c_exchange = "SMART";
  131.     c.c_primary_exch = "";
  132.     c.c_currency = "USD";
  133.     c.c_local_symbol = "";
  134.     tws_request_realtime_bars(ti, 4, &c, 5, "TRADES", 0);
  135.  
  136.  
  137.  
  138.     while(0 == tws_event_process(ti));
  139.  
  140.     tws_destroy(ti);
  141.     return 0;
  142. }
  #2 (permalink)  
Antiguo 08/05/2009, 13:36
Avatar de Eternal Idol  
Fecha de Ingreso: mayo-2004
Ubicación: Lucentum
Mensajes: 6.192
Antigüedad: 20 años
Puntos: 74
Respuesta: Multiplataforma

¿Que compilador estas usando? ¿Que parametros? ¿Cual es el output exacto del mismo?
__________________
¡Peron cumple, Evita dignifica! VIVA PERON CARAJO
  #3 (permalink)  
Antiguo 08/05/2009, 16:34
 
Fecha de Ingreso: abril-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Respuesta: Multiplataforma

Al final he conseguido que funcionara en windows con:
g++ -DWINDOWS -D_REENTRANT -Wall -Wsign-compare -Wfloat-equal -g -c twsapi.c callbacks.c example.cpp
g++ twsapi.o callbacks.o example.o -o EXECUTABLE_NAME.exe -lws2_32

I en Linux:
g++ -D_REENTRANT -Wall -Wsign-compare -Wfloat-equal -g -c twsapi.c callbacks.c example.cpp
g++ twsapi.o callbacks.o example.o -o a.out

Culpa mía, por mi ínfimo conocimiento del tema, makefiles, etc ( -DWINDOWS -D_REENTRANT, ni idea para que sirven).

Algún sitio donde se explique un poco todo?
He buscado ya, pero no he sabido encontrar casi nada.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:54.