Skip to content

Commit c1f1477

Browse files
committed
Fix cpprofiler compilation on Windows
1 parent 9f2605d commit c1f1477

5 files changed

Lines changed: 36 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ endif()
553553
gecode_link_component(kernel support)
554554
if(GECODE_ENABLE_SEARCH)
555555
gecode_link_component(search kernel)
556+
if(WIN32 AND GECODE_ENABLE_CPPROFILER)
557+
gecode_link_component(search ws2_32)
558+
endif()
556559
endif()
557560
if(GECODE_ENABLE_INT_VARS)
558561
gecode_link_component(int kernel)

Makefile.in

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export EXAMPLES_EXTRA_CXXFLAGS = @EXAMPLES_EXTRA_CXXFLAGS@
7575

7676
export QT_CPPFLAGS = @QTDEFINES@ @QTINCLUDES@
7777
export LINKQT = @QTLIBS@
78+
export LINKCPPROFILER = @LINKCPPROFILER@
7879
export MPFR_CPPFLAGS = @GMP_CPPFLAGS@ @MPFR_CPPFLAGS@
7980
ifeq "@enable_mpfr@" "yes"
8081
export LINKMPFR = @MPFR_LIB_PATH@ @GMP_LIB_PATH@ @MPFR_LINK@ @GMP_LINK@
@@ -1545,7 +1546,7 @@ $(KERNELDLL): $(KERNELOBJ) $(SUPPORTDLL)
15451546
$(CREATELINK) $@ $(@:%$(DLLSUFFIX)=%$(SOSUFFIX))
15461547
$(SEARCHDLL): $(SEARCHOBJ) $(SUPPORTDLL) $(KERNELDLL)
15471548
$(CXX) $(DLLFLAGS) $(SEARCHOBJ) $(SEARCHSONAME) \
1548-
@DLLPATH@ $(LINKSUPPORT) $(LINKKERNEL) \
1549+
@DLLPATH@ $(LINKSUPPORT) $(LINKKERNEL) $(LINKCPPROFILER) \
15491550
@LINKOUTPUT@$(SEARCHDLL)
15501551
$(CREATELINK) $@ $(@:%$(DLLSUFFIX)=%$(SOLINKSUFFIX))
15511552
$(CREATELINK) $@ $(@:%$(DLLSUFFIX)=%$(SOSUFFIX))
@@ -1622,7 +1623,7 @@ $(SEARCHRC):
16221623
endif
16231624
$(SEARCHDLL) $(SEARCHLIB): $(SEARCHOBJ) $(SEARCHRES) $(SUPPORTDLL) $(KERNELDLL)
16241625
$(CXX) $(DLLFLAGS) $(SEARCHOBJ) $(SEARCHRES) \
1625-
@DLLPATH@ @LINKOUTPUT@$(SEARCHDLL) $(GLDFLAGS)
1626+
@DLLPATH@ @LINKOUTPUT@$(SEARCHDLL) $(GLDFLAGS) $(LINKCPPROFILER)
16261627
$(FIXMANIFEST) $(SEARCHDLL).manifest
16271628
$(MANIFEST) -manifest $(SEARCHDLL).manifest \
16281629
-outputresource:$(SEARCHDLL)\;2
@@ -1781,13 +1782,13 @@ examples/%$(EXESUFFIX): examples/%$(OBJSUFFIX) examples/%$(EXESUFFIX).res \
17811782
$(ALLLIB)
17821783
$(CXX) @EXEOUTPUT@$@ $< $@.res \
17831784
$(DLLPATH) $(CXXFLAGS) \
1784-
$(LINKALL) $(GLDFLAGS) $(LINKQT)
1785+
$(LINKALL) $(GLDFLAGS) $(LINKQT) $(LINKCPPROFILER)
17851786
$(FIXMANIFEST) $@.manifest
17861787
$(MANIFEST) -manifest $@.manifest -outputresource:$@\;1
17871788
else
17881789
examples/%$(EXESUFFIX): examples/%$(OBJSUFFIX) $(ALLLIB)
17891790
$(CXX) @EXEOUTPUT@$@ $< $(DLLPATH) $(CXXFLAGS) \
1790-
$(LINKALL) $(GLDFLAGS) $(LINKQT)
1791+
$(LINKALL) $(GLDFLAGS) $(LINKQT) $(LINKCPPROFILER)
17911792
$(FIXMANIFEST) $@.manifest
17921793
$(MANIFEST) -manifest $@.manifest -outputresource:$@\;1
17931794
endif
@@ -1801,7 +1802,7 @@ TESTRES =
18011802
endif
18021803
$(TESTEXE): $(TESTOBJ) $(TESTRES) $(ALLLIB)
18031804
$(CXX) @EXEOUTPUT@$@ $(TESTOBJ) $(TESTRES) $(DLLPATH) $(CXXFLAGS) \
1804-
$(LINKALL) $(GLDFLAGS) $(LINKQT)
1805+
$(LINKALL) $(GLDFLAGS) $(LINKQT) $(LINKCPPROFILER)
18051806
$(FIXMANIFEST) $@.manifest $(DLLSUFFIX)
18061807
$(MANIFEST) -manifest $@.manifest -outputresource:$@\;1
18071808

@@ -1821,8 +1822,8 @@ FLATZINCEXERES =
18211822
endif
18221823
$(FLATZINCEXE): $(FLATZINCEXEOBJ) $(FLATZINCEXERES) $(ALLLIB)
18231824
$(CXX) @EXEOUTPUT@$@ $(FLATZINCEXEOBJ) $(FLATZINCEXERES) \
1824-
$(DLLPATH) $(CXXFLAGS) \
1825-
$(LINKALL) $(GLDFLAGS) $(LINKSTATICQT)
1825+
$(DLLPATH) $(CXXFLAGS) \
1826+
$(LINKALL) $(GLDFLAGS) $(LINKSTATICQT) $(LINKCPPROFILER)
18261827
$(FIXMANIFEST) $@.manifest
18271828
$(MANIFEST) -manifest $@.manifest -outputresource:$@\;1
18281829

configure

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ HAVEBISON
672672
HAVE_FLEXBISON
673673
HAVEFLEX
674674
enable_cpprofiler
675+
LINKCPPROFILER
675676
enable_cbs
676677
enable_gist
677678
enable_qt
@@ -13801,11 +13802,21 @@ then :
1380113802
enableval=$enable_cpprofiler;
1380213803
fi
1380313804

13805+
1380413806
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build with support for CPProfiler" >&5
1380513807
printf %s "checking whether to build with support for CPProfiler... " >&6; }
1380613808
if test "${enable_cpprofiler:-yes}" = "yes"; then
1380713809
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1380813810
printf "%s\n" "yes" >&6; }
13811+
if test "${host_os}" = "windows"; then
13812+
if test "${ac_cv_cxx_compiler_vendor}" = "microsoft"; then
13813+
LINKCPPROFILER=ws2_32.lib
13814+
13815+
else
13816+
LINKCPPROFILER=-lws2_32
13817+
13818+
fi
13819+
fi
1380913820
enable_cpprofiler=yes
1381013821

1381113822

gecode.m4

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,9 +1399,17 @@ AC_DEFUN([AC_GECODE_CPPROFILER],
13991399
AC_ARG_ENABLE([cpprofiler],
14001400
AS_HELP_STRING([--enable-cpprofiler],
14011401
[build with support for CPProfiler @<:@default=yes@:>@]))
1402+
AC_SUBST(LINKCPPROFILER, [])
14021403
AC_MSG_CHECKING(whether to build with support for CPProfiler)
14031404
if test "${enable_cpprofiler:-yes}" = "yes"; then
14041405
AC_MSG_RESULT(yes)
1406+
if test "${host_os}" = "windows"; then
1407+
if test "${ac_cv_cxx_compiler_vendor}" = "microsoft"; then
1408+
AC_SUBST(LINKCPPROFILER, [ws2_32.lib])
1409+
else
1410+
AC_SUBST(LINKCPPROFILER, [-lws2_32])
1411+
fi
1412+
fi
14051413
AC_SUBST(enable_cpprofiler, yes)
14061414
AC_DEFINE([GECODE_HAS_CPPROFILER],[],[Whether CPProfiler support available])
14071415
else

gecode/search/cpprofiler/connector.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
#include <vector>
4343
#include <cstring>
4444

45-
#ifdef WIN32
45+
#if defined(_WIN32)
4646

4747
#include <winsock2.h>
4848
#include <ws2tcpip.h>
49+
#if defined(_MSC_VER)
4950
#pragma comment(lib, "Ws2_32.lib")
5051
#pragma comment(lib, "Mswsock.lib")
5152
#pragma comment(lib, "AdvApi32.lib")
53+
#endif
5254

5355
#include <basetsd.h>
5456
typedef SSIZE_T ssize_t;
@@ -270,7 +272,7 @@ namespace Gecode { namespace CPProfiler {
270272
struct addrinfo hints, *servinfo, *p;
271273
int rv;
272274

273-
#ifdef WIN32
275+
#if defined(_WIN32)
274276
// Initialise Winsock.
275277
WSADATA wsaData;
276278
int startupResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
@@ -297,7 +299,7 @@ namespace Gecode { namespace CPProfiler {
297299
}
298300

299301
if (::connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
300-
#ifdef WIN32
302+
#if defined(_WIN32)
301303
closesocket(sockfd);
302304
#else
303305
close(sockfd);
@@ -378,7 +380,7 @@ namespace Gecode { namespace CPProfiler {
378380

379381
inline void
380382
Connector::disconnect() {
381-
#ifdef WIN32
383+
#if defined(_WIN32)
382384
closesocket(sockfd);
383385
#else
384386
close(sockfd);

0 commit comments

Comments
 (0)