Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile for windows? #5

Open
bw4sz opened this issue Jul 3, 2017 · 7 comments
Open

Compile for windows? #5

bw4sz opened this issue Jul 3, 2017 · 7 comments

Comments

@bw4sz
Copy link

bw4sz commented Jul 3, 2017

@yujiali Thanks for making this code available.

Do you have a sense if this can compile for windows?
I am running make (g++) from within git bash.

I bypassed make download by downloading the library from source and extracting it.

Make all ran perfectly.

$ make all
g++ -fPIC \
    -c gco_source/LinkedBlockList.cpp \
    -o gco_source/LinkedBlockList.o
gco_source/LinkedBlockList.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
g++ -fPIC \
    -c gco_source/graph.cpp \
    -o gco_source/graph.o
gco_source/graph.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
g++ -fPIC \
    -c gco_source/maxflow.cpp \
    -o gco_source/maxflow.o
gco_source/maxflow.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
g++ -fPIC \
    -c gco_source/GCoptimization.cpp \
    -o gco_source/GCoptimization.o
gco_source/GCoptimization.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
gco_source/GCoptimization.cpp:18:0: warning: "NOMINMAX" redefined [enabled by default]
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../include/c++/4.6.3/i686-w64-mingw32/bits/os_defines.h:46:0: note: this is the location of the previous definition
gco_source/GCoptimization.cpp:21:23: warning: 'GCO_CLOCKS_PER_SEC' initialized and declared 'extern' [enabled by default]
g++ -fPIC \
    -c cgco.cpp \
    -o cgco.o
cgco.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
g++ -shared -fPIC \
    gco_source/LinkedBlockList.o \
    gco_source/graph.o \
    gco_source/maxflow.o \
    gco_source/GCoptimization.o \
    cgco.o \
    -o libcgco.so

looking good so far

image

$ make test_wrapper
g++ -L. test_wrapper.cpp \
    -o test_wrapper -lcgco
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lcgco
collect2: ld returned 1 exit status
make: *** [test_wrapper] Error 1

Any suggestions on where to go from here?

Obviously, running the python code doesn't work yet.

Ben@Laptop MINGW64 ~/Documents/pygco (master)
$ python test.py
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    import pygco
  File "C:\Users\Ben\Documents\pygco\pygco.py", line 3, in <module>
    from cgco import _cgco
  File "C:\Users\Ben\Documents\pygco\cgco.py", line 25, in <module>
    _cgco = np.ctypeslib.load_library(_CGCO_LIB_NAME, _CGCO_LIB_PATH)
  File "C:\Program Files\Python35\lib\site-packages\numpy\ctypeslib.py", line 150, in load_library
    return ctypes.cdll[libpath]
  File "C:\Program Files\Python35\lib\ctypes\__init__.py", line 422, in __getitem__
    return getattr(self, name)
  File "C:\Program Files\Python35\lib\ctypes\__init__.py", line 417, in __getattr__
    dll = self._dlltype(name)
  File "C:\Program Files\Python35\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

Again, thanks for the help.

@yujiali
Copy link
Owner

yujiali commented Jul 13, 2017

Hi @bw4sz ,

I have no experience of building this on Windows. In your screenshot there is no libcgco.so in the current directory, maybe it is not generated properly.

@bw4sz
Copy link
Author

bw4sz commented Jul 19, 2017

I'll post on stack overflow, but just confirming, in that screenshot above there is a file called libcgco.so (in green), I am I seeing something different, or not following? That directory is in path. Either way I'll report back if I get it to build, perhaps it will help a future user. Thanks

@mohammadkamalzare
Copy link

mohammadkamalzare commented Oct 18, 2017

Hi @bw4sz ,
to make this project on windows , you need to first add __declspec(dllexport) after each extrern "C" in both cgco.cpp and cgco.h , and then compile whole project like this:

cl gco_source\LinkedBlockList.cpp /link /out:LinkedBlockList.obj
cl gco_source\graph.cpp /link /out:graph.obj
cl gco_source\maxflow.cpp /link /out:maxflow.obj
cl gco_source\GCoptimization.cpp /link /out:GCoptimization.obj
cl cgco.cpp /link /out:cgco.obj
cl LinkedBlockList.obj graph.obj maxflow.obj GCoptimization.obj cgco.obj /link /dll /out:libcgco.dll

to use cl compiler you should run Developer Command Prompt for VS_version_
and run C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat (or C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall amd64 if your python use x64 compiler)

and then you need to change cgco.py and replace _CGCO_LIB_NAME = 'libcgco.so' with _CGCO_LIB_NAME = 'libcgco.dll' and then every thing goes OK.

@Borda
Copy link
Contributor

Borda commented Oct 18, 2017

The *.so is Linux library, Windows creates static or dynamic libraries *.dll as mentioned above.
@mohammadkamalzare thanks, I will try to update it in repo, and test it in CI - AppVeyor

@Mac-FF
Copy link

Mac-FF commented Dec 21, 2017

Hello @mohammadkamalzare and @Borda,

I try to compile this project with Windows7 and "mingw32-make.exe".
I use "Developer Command Prompt for VS 2017" for cl command and have issues in line:
cl cgco.cpp /link /out:cgco.obj
Example (files from gco_source and gco is in the same folder) :

D:\Projects\pyGCO\test> cl cgco.cpp /link /out:cgco.obj

(...)

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.1
1.25503\include\type_traits(2342): warning C4577: 'noexcept' used with no except
ion handling mode specified; termination on exception is not guaranteed. Specify
 /EHsc
Microsoft (R) Incremental Linker Version 14.11.25547.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:cgco.exe
/out:cgco.obj
cgco.obj
LINK : fatal error LNK1149: output filename matches input filename 'D:\Projects\
pyGCO\test\cgco.obj'

If I change command on:
cl cgco.cpp /link /out:cgco77777777.obj
I have this issue:

(...)
/out:cgco.exe
/out:cgco77777777.obj
cgco.obj
   Creating library cgco77777777.lib and object cgco77777777.exp
LINK : fatal error LNK1561: entry point must be defined

Do you have any idea to resolve this problem?

jotaf98 pushed a commit to jotaf98/pygco that referenced this issue Aug 17, 2018
@jotaf98
Copy link

jotaf98 commented Aug 17, 2018

Hi everyone, I managed to compile on Windows 10 following @mohammadkamalzare 's advice (Thanks!!).

I packaged it as Pull Request #8.

@jotaf98
Copy link

jotaf98 commented Aug 17, 2018

@Mac-FF : I got the error too but it still compiles correctly. It's because it creates the .obj file (which we want) but also attempts to link and create an .exe. Only the last step fails (which is not needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants