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

cannot compile on Windows #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

garfieldnate
Copy link

Using VC++ 14.0, I cannot compile from source. The problem is an ambiguity caused by the << operator in common.h in the string_buffer class. Here's the error output:

C:\...\CRF++-0.58>nmake -f Makefile.ms
vc.in

Microsoft (R) Program Maintenance Utility Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DDLL_EXPORT  -DUNICODE -D_UNICODE  -DHAVE_WINDOWS_H -DVER
SION="\"@VERSION@\"" -DPACKAGE="\"@PACKAGE@\"" -c tagger.cpp
tagger.cpp
c:\...\crf++-0.58\tagger.h(174): warni
ng C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data

tagger.cpp(336): warning C4267: '=': conversion from 'size_t' to 'unsigned short
', possible loss of data
tagger.cpp(758): error C2593: 'operator <<' is ambiguous
c:\...\crf++-0.58\common.h(224): note:
 could be 'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(const std::ba
sic_string<char,std::char_traits<char>,std::allocator<char>> &)'
c:\...\crf++-0.58\common.h(220): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(const char *)
'
c:\...\crf++-0.58\common.h(216): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(char)'
c:\...\crf++-0.58\common.h(215): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(unsigned long
)'
c:\...\crf++-0.58\common.h(214): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(unsigned int)
'
c:\...\crf++-0.58\common.h(213): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(unsigned shor
t)'
c:\...\crf++-0.58\common.h(212): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(long)'
c:\...\crf++-0.58\common.h(211): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(int)'
c:\...\crf++-0.58\common.h(210): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(short)'
c:\...\crf++-0.58\common.h(209): note:
 or       'CRFPP::string_buffer &CRFPP::string_buffer::operator <<(double)'
tagger.cpp(758): note: while trying to match the argument list '(CRFPP::string_b
uffer, size_t)'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0
\VC\BIN\amd64\cl.EXE"' : return code '0x2'
Stop.

@garfieldnate
Copy link
Author

For now, my fix was to cast the offending size_t type variable to unsigned int on line 758 of tagger.cpp:

os_ << "# " << (unsigned int) n << " " << prob() << '\n';

This creates a compiler warning, and I don't know if it is functioning correctly, but it seems usable. I do not think n will ever be bigger than an unsigned int can contain.

@tavianator
Copy link

Does #17 fix it for you?

@garfieldnate
Copy link
Author

Sorry, I should have been more specific about what I was doing. The error I reported was for version 0.58. I checked out master, though, and it still gave me an error, though a different one. I applied #17 and the problem persists with both VC 12.0 and 14.0. Here's the output:

C:\...\crfpp>nmake -f Makefile.msvc

Microsoft (R) Program Maintenance Utility Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c encoder.
cpp
encoder.cpp
C:\...\crfpp\tagger.h(174): warning C4
267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data
encoder.cpp(115): warning C4267: '+=': conversion from 'size_t' to 'int', possib
le loss of data
encoder.cpp(211): warning C4267: '=': conversion from 'size_t' to 'unsigned shor
t', possible loss of data
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c feature.
cpp
feature.cpp
C:\...\crfpp\tagger.h(174): warning C4
267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data
feature.cpp(80): warning C4267: 'initializing': conversion from 'size_t' to 'int
', possible loss of data
feature.cpp(80): warning C4267: 'initializing': conversion from 'size_t' to 'con
st int', possible loss of data
feature.cpp(138): warning C4267: '=': conversion from 'size_t' to 'unsigned int'
, possible loss of data
feature.cpp(139): warning C4267: '=': conversion from 'size_t' to 'unsigned shor
t', possible loss of data
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c feature_
cache.cpp
feature_cache.cpp
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c libcrfpp
.cpp
libcrfpp.cpp
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c feature_
index.cpp
feature_index.cpp
feature_index.cpp(118): warning C4267: '+=': conversion from 'size_t' to 'unsign
ed int', possible loss of data
feature_index.cpp(177): warning C4267: '=': conversion from 'size_t' to 'unsigne
d int', possible loss of data
feature_index.cpp(269): warning C4267: '+=': conversion from 'size_t' to 'int',
possible loss of data
feature_index.cpp(432): warning C4267: 'initializing': conversion from 'size_t'
to 'unsigned int', possible loss of data
feature_index.cpp(434): warning C4267: 'initializing': conversion from 'size_t'
to 'unsigned int', possible loss of data
feature_index.cpp(437): warning C4267: '=': conversion from 'size_t' to 'unsigne
d int', possible loss of data
C:\...\crfpp\darts.h(180): warning C42
67: '=': conversion from 'size_t' to 'unsigned int', possible loss of data
C:\...\crfpp\darts.h(129): note: while
 compiling class template member function 'size_t CRFPP::Darts::DoubleArrayImpl<
char,unsigned char,int,unsigned int,CRFPP::Darts::Length<char>>::insert(const st
d::vector<CRFPP::Darts::DoubleArrayImpl<char,unsigned char,int,unsigned int,CRFP
P::Darts::Length<char>>::node_t,std::allocator<_Ty>> &)'
        with
        [
            _Ty=CRFPP::Darts::DoubleArrayImpl<char,unsigned char,int,unsigned in
t,CRFPP::Darts::Length<char>>::node_t
        ]
C:\...\crfpp\darts.h(292): note: see r
eference to function template instantiation 'size_t CRFPP::Darts::DoubleArrayImp
l<char,unsigned char,int,unsigned int,CRFPP::Darts::Length<char>>::insert(const
std::vector<CRFPP::Darts::DoubleArrayImpl<char,unsigned char,int,unsigned int,CR
FPP::Darts::Length<char>>::node_t,std::allocator<_Ty>> &)' being compiled
        with
        [
            _Ty=CRFPP::Darts::DoubleArrayImpl<char,unsigned char,int,unsigned in
t,CRFPP::Darts::Length<char>>::node_t
        ]
C:\...\crfpp\feature_index.h(125): not
e: see reference to class template instantiation 'CRFPP::Darts::DoubleArrayImpl<
char,unsigned char,int,unsigned int,CRFPP::Darts::Length<char>>' being compiled
C:\...\crfpp\darts.h(189): warning C41
46: unary minus operator applied to unsigned type, result still unsigned
C:\...\crfpp\darts.h(201): warning C42
67: '=': conversion from 'size_t' to 'int', possible loss of data
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c node.cpp

node.cpp
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c param.cp
p
param.cpp
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c path.cpp

path.cpp
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c tagger.c
pp
tagger.cpp
C:\...\crfpp\tagger.h(174): warning C4
267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data
tagger.cpp(336): warning C4267: '=': conversion from 'size_t' to 'unsigned short
', possible loss of data
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c lbfgs.cp
p
lbfgs.cpp
        link /link /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE ADVAPI32.LIB /
out:libcrfpp.dll encoder.obj feature.obj feature_cache.obj libcrfpp.obj  feature
_index.obj node.obj param.obj path.obj tagger.obj lbfgs.obj /dll
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library libcrfpp.lib and object libcrfpp.exp
Generating code
Finished generating code
        cl /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 -I. -I.. -D_CR
T_SECURE_NO_DEPRECATE -DCRFPP_DLL -DCRFPP_DLL_EXPORT -DDLL_EXPORT  -DUNICODE -D_
UNICODE  -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" -c crf_lear
n.cpp
crf_learn.cpp
crf_learn.cpp(9): fatal error C1083: Cannot open include file: 'winmain.h': No s
uch file or directory
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0
\VC\BIN\amd64\cl.EXE"' : return code '0x2'
Stop.

@garfieldnate
Copy link
Author

Everything compiles just fine when I change #include "winmain.h" to #include <windows.h>, even before your patch (though I haven't tested the functionality of the resulting binaries).

The command I'm running is nmake -f Makefile.msvc in a VS2015 x64 Native Tools Command Prompt. OS is Windows 8. nmake version 14.00.23506.0.

@garfieldnate
Copy link
Author

Please note that I have not checked the source changes on other platforms, but the extra Makefiles should be useful to other Windows users.

@tavianator
Copy link

Right, for the winmain.h fix you need #15

@garfieldnate
Copy link
Author

Ah. So what was the patch in #17 for? Or has that been fixed since?

@tavianator
Copy link

It fixes the build with mingw. I thought it might have helped your initial issue as well.

@garfieldnate
Copy link
Author

Thanks for your help. I don't know if the repo will ever be updated, but hopefully this will help the next person. To compile easily with MSVC you need #15 and a few more makefiles. I added the needed makefile for the Java dll, but I didn't do it for the other bindings; it shouldn't be too hard to make the other ones with this as an example, though.

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

Successfully merging this pull request may close these issues.

3 participants