Я пытаюсь заставить библиотеку C ++, используемую одним из моих классов, работать как в Windows, так и в Linux (она была разработана для Linux).Код для этого здесь (он не большой).Я компилирую с MinGW в 64-битной Windows 7.
У меня проблемы с HTTPInputStream на последнем этапе компоновки.Я отредактировал верхнюю часть HTTPInputStream.cpp так, чтобы включения выглядели так:
#include <sstream>
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#ifdef WIN32
#include <Winsock.h>
#define bzero(p, l) memset(p, 0, l)
#else
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#endif
#include "CS240Exception.h"
#include "StringUtil.h"
#include "HTTPInputStream.h"
Вот мой make-файл:
CPP = g++ -g
CS240_UTIL_H = utils/inc/CommandRunner.h utils/inc/FileInputStream.h utils/inc/FileSystem.h utils/inc/HTMLToken.h utils/inc/HTMLTokenizer.h utils/inc/HTTPInputStream.h utils/inc/StringUtil.h utils/inc/URLInputStream.h utils/inc/UnitTest.h utils/inc/CS240Exception.h utils/inc/InputStream.h
CS240_UTIL_CPP = utils/src/CommandRunner.cpp utils/src/FileInputStream.cpp utils/src/FileSystem.cpp utils/src/HTMLToken.cpp utils/src/HTMLTokenizer.cpp utils/src/HTTPInputStream.cpp utils/src/StringUtil.cpp utils/src/URLInputStream.cpp
CS240_UTIL_OBJ = utils/obj/CommandRunner.o utils/obj/FileInputStream.o utils/obj/FileSystem.o utils/obj/HTMLToken.o utils/obj/HTMLTokenizer.o utils/obj/HTTPInputStream.o utils/obj/StringUtil.o utils/obj/URLInputStream.o
all: clean lib
lib: $(CS240_UTIL_OBJ)
$(CPP) -o lib/cs240utils.LIB -I utils/inc $(CS240_UTIL_OBJ)
clean:
@- rm utils/obj/*.o
#library files
utils/obj/CommandRunner.o: utils/src/CommandRunner.cpp utils/inc/CommandRunner.h
$(CPP) -c -o utils/obj/CommandRunner.o -I utils/inc utils/src/CommandRunner.cpp
utils/obj/FileInputStream.o: utils/src/FileInputStream.cpp utils/inc/FileInputStream.h
$(CPP) -c -o utils/obj/FileInputStream.o -I utils/inc utils/src/FileInputStream.cpp
utils/obj/FileSystem.o: utils/src/FileSystem.cpp utils/inc/FileSystem.h
$(CPP) -c -o utils/obj/FileSystem.o -I utils/inc utils/src/FileSystem.cpp
utils/obj/HTMLToken.o: utils/src/HTMLToken.cpp utils/inc/HTMLToken.h
$(CPP) -c -o utils/obj/HTMLToken.o -I utils/inc utils/src/HTMLToken.cpp
utils/obj/HTMLTokenizer.o: utils/src/HTMLTokenizer.cpp utils/inc/HTMLTokenizer.h
$(CPP) -c -o utils/obj/HTMLTokenizer.o -I utils/inc utils/src/HTMLTokenizer.cpp
utils/obj/HTTPInputStream.o: utils/src/HTTPInputStream.cpp utils/inc/HTTPInputStream.h
$(CPP) -c -o utils/obj/HTTPInputStream.o -I utils/inc utils/src/HTTPInputStream.cpp
utils/obj/StringUtil.o: utils/src/StringUtil.cpp utils/inc/StringUtil.h
$(CPP) -c -o utils/obj/StringUtil.o -I utils/inc utils/src/StringUtil.cpp
utils/obj/URLInputStream.o: utils/src/URLInputStream.cpp utils/inc/URLInputStream.h
$(CPP) -c -o utils/obj/URLInputStream.o -I utils/inc utils/src/URLInputStream.cpp
А вот вывод этого make-файла:
I:>make -f testmake.txt
g++ -g -c -o utils/obj/CommandRunner.o -I utils/include utils/src/CommandRunner.cpp
g++ -g -c -o utils/obj/FileInputStream.o -I utils/include utils/src/FileInputStream.cpp
g++ -g -c -o utils/obj/FileSystem.o -I utils/include utils/src/FileSystem.cpp
g++ -g -c -o utils/obj/HTMLToken.o -I utils/include utils/src/HTMLToken.cpp
g++ -g -c -o utils/obj/HTMLTokenizer.o -I utils/include utils/src/HTMLTokenizer.cpp
g++ -g -c -o utils/obj/HTTPInputStream.o -I utils/include utils/src/HTTPInputStream.cpp
g++ -g -c -o utils/obj/StringUtil.o -I utils/include utils/src/StringUtil.cpp
g++ -g -c -o utils/obj/URLInputStream.o -I utils/include utils/src/URLInputStream.cpp
g++ -g -o lib/cs240utils.LIB -I utils/include utils/obj/CommandRunner.o utils/obj/FileInputStream.o utils/obj/FileSystem.o utils/obj/HTMLToken.o utils/obj/HTMLTokenizer.o utils/obj/HTTPInputStream.o utils/obj/StringUtil.o utils/obj/URLInputStream.o
utils/obj/HTTPInputStream.o:I:/utils/src/HTTPInputStream.cpp:246: undefined reference to `_imp__gethostbyname@4'
utils/obj/HTTPInputStream.o:I:/utils/src/HTTPInputStream.cpp:255: undefined reference to `_imp__htons@4'
utils/obj/HTTPInputStream.o:I:/utils/src/HTTPInputStream.cpp:258: undefined reference to `_imp__socket@12'
utils/obj/HTTPInputStream.o:I:/utils/src/HTTPInputStream.cpp:264: undefined reference to `_imp__connect@12'
c:/strawberry/c/bin/../lib/gcc/i686-w64-mingw32/4.4.3/../../../../i686-w64-mingw
32/lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o): In function `main':/opt/W64_156151-src.32/build-crt/../mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
make: *** [lib] Error 1
Я много гуглял по этому поводу и не нашел ничего, что решило бы это.Добавление -lwsock32
в командную строку не помогает.Есть идеи?