eulerto / pg_similarity

set of functions and operators for executing similarity queries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Native MSVC build support

ringerc opened this issue · comments

Hi

A recent stack overflow poster showed interest in using this extension on Windows.

I'm sure you find Windows as fun as I do ;-) . Nonetheless, I noticed you had instructions on how to build for MSVC. There's actually a much simpler way to do it if you want to, by providing or generating MSBuild project file. I wrote some details about it in a recent blog post:

Compiling PostgreSQL extensions with MSVC.

It's a relatively non-awful process, for Windows development, and doesn't require a full PostgreSQL source tree to be configured and built.

I'm not asking you to do anything. I just thought I'd mention the option in case you - or someone who has a reason to bother to contribute Windows support - is interested.

Craig, I commented on the stack overflow post. During the weekend I tried to figure out without success to build pg_similarity without the postgres source tree. :( However, I succeded building pg_similarity with source tree in 9.3 and 9.4.

I'm posting part of the MSVC log in case you want to take a look. Let me know if you want the try-without-success version:

Project "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\myext\myext.vcxproj" on node 2 (rebuild target(s)).
_PrepareForClean:
Deleting file "Release\myext.lastbuildstate".
InitializeBuildStatus:
Touching "Release\myext.unsuccessfulbuild".
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /I"C:\Program Files\PostgreSQL\9.3\include\server\port\win32_msvc" /I"C:\Program Files\PostgreSQL\9.3\include\server\port\win32" /I"C:\Program Files\PostgreSQL\9.3\include\server" /I"C:\Program Files\PostgreSQL\9.3\include" /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D WIN32 /Gm- /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release" /Fd"Release\vc100.pdb" /Gd /TC /analyze- /errorReport:prompt block.c cosine.c dice.c euclidean.c hamming.c jaccard.c jaro.c levenshtein.c matching.c mongeelkan.c needlemanwunsch.c overlap.c qgram.c similarity.c similarity_gin.c smithwaterman.c smithwatermangotoh.c soundex.c tokenizer.c
block.c
cosine.c
dice.c
euclidean.c
hamming.c
jaccard.c
jaro.c
levenshtein.c
matching.c
mongeelkan.c
needlemanwunsch.c
overlap.c
qgram.c
similarity.c
similarity_gin.c
smithwaterman.c
smithwatermangotoh.c
soundex.c
tokenizer.c
tokenizer.c(48): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
tokenizer.c(248): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
tokenizer.c(334): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
tokenizer.c(380): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
tokenizer.c(405): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
tokenizer.c(423): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
tokenizer.c(521): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(188) : see declaration of 'strncpy'
Link:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.dll" /NOLOGO "C:\Program Files\PostgreSQL\9.3\lib\postgres.lib" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST:NO /DEBUG /PDB:"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.pdb" /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.lib" /MACHINE:X86 /DLL Release\block.obj
Release\cosine.obj
Release\dice.obj
Release\euclidean.obj
Release\hamming.obj
Release\jaccard.obj
Release\jaro.obj
Release\levenshtein.obj
Release\matching.obj
Release\mongeelkan.obj
Release\needlemanwunsch.obj
Release\overlap.obj
Release\qgram.obj
Release\similarity.obj
Release\similarity_gin.obj
Release\smithwaterman.obj
Release\smithwatermangotoh.obj
Release\soundex.obj
Release\tokenizer.obj
Creating library C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.lib and object C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.exp
block.obj : error LNK2001: unresolved external symbol _Float8GetDatum
block.obj : error LNK2001: unresolved external symbol _elog_start
block.obj : error LNK2001: unresolved external symbol _pg_detoast_datum
block.obj : error LNK2001: unresolved external symbol _DirectFunctionCall2Coll
block.obj : error LNK2001: unresolved external symbol _errstart
block.obj : error LNK2001: unresolved external symbol _errmsg
block.obj : error LNK2001: unresolved external symbol _textout
block.obj : error LNK2001: unresolved external symbol _DirectFunctionCall1Coll
block.obj : error LNK2001: unresolved external symbol _elog_finish
block.obj : error LNK2001: unresolved external symbol _errcode
block.obj : error LNK2001: unresolved external symbol _errfinish
jaro.obj : error LNK2001: unresolved external symbol _pfree
jaro.obj : error LNK2001: unresolved external symbol _palloc
similarity.obj : error LNK2001: unresolved external symbol _DefineCustomIntVariable
similarity.obj : error LNK2001: unresolved external symbol _DefineCustomBoolVariable
similarity.obj : error LNK2001: unresolved external symbol _DefineCustomEnumVariable
similarity.obj : error LNK2001: unresolved external symbol _DefineCustomRealVariable
similarity_gin.obj : error LNK2001: unresolved external symbol _text_to_cstring
similarity_gin.obj : error LNK2001: unresolved external symbol _cstring_to_text_with_len
C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\Release\myext.dll : fatal error LNK1120: 19 unresolved externals
Done Building Project "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\myext\myext\myext.vcxproj" (rebuild target(s)) -- FAILED.

That's odd, given that postgres.lib is on the linker target path. Is it possible you're building a 32-bit library binary but pointing the linker to the 64-bit postgres.lib? It looks like you may be, but I find MSVC's cl command lines pretty opaque so I'm not completely sure. I'd have expected an error or warning were this the case though.

It seems a problem in my environment. I changed Linker > Advanced > Target Machine to x64 and the only message was:

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

I tried to reset my VS settings but without success. I reinstalled all MS Visual Studio 2010 but it remains the same problem.

Windows Server 2012 R2 64-bit (version 6.3 build 9600)
Visual Studio 2010 Express (10.0.30319.1)
.Net Framework 4.5.51641

Commit 0a9226a added support for native MSVC build. Thanks for your guidance @ringerc .