mongodb-labs / mongorover

Intern project - MongoDB driver for the Lua programming language - This Repository is NOT a supported MongoDB product
Apache License 2.0
55 stars 10 forks source link

LuaRocks Install Compiler Errors Visual Studio 2010 #63

Closed TDycks closed 7 years ago

TDycks commented 7 years ago

Successfully build and installed the Mongo C Driver v1.3.5 to the C:\libmongoc Directory of my Windows 10 PC using the GitHub documentation on the Mongo Driver website.

When attempting to install mongorover via LuaRocks pointing to my libmongoc and libbson directories I get the following error:

C:\Storage\lua\rocks>luarocks install mongorover LIBBSON_DIR=C:/libmongoc LIBMONGOC_DIR=C:/libmongoc Installing http://luarocks.org/repositories/rocks/mongorover-0.1-1.src.rock... cl /MD /O2 -c -Foc_wrapper/mongo-module.obj -IC:/Program Files (x86)/Lua/5.1/include c_wrapper/mongo-module.c -IC:/libmongoc/include/libmongoc-1.0 -IC:/libmongoc/include/libbson-1.0 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

mongo-module.c c_wrapper/mongo-module.c(24) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int' c:\users\panfi\appdata\local\temp\luarocks_mongorover-0.1-1-9831\mongorover\c_wrapper\mongo-module.c(29) : warning C4716: 'lua_mongo_get_object_id' : must return a value cl /MD /O2 -c -Foc_wrapper/lua-mongoc-client.obj -IC:/Program Files (x86)/Lua/5.1/include c_wrapper/lua-mongoc-client.c -IC:/libmongoc/include/libmongoc-1.0 -IC:/libmongoc/include/libbson-1.0 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

lua-mongoc-client.c cl /MD /O2 -c -Foc_wrapper/lua-mongoc-database.obj -IC:/Program Files (x86)/Lua/5.1/include c_wrapper/lua-mongoc-database.c -IC:/libmongoc/include/libmongoc-1.0 -IC:/libmongoc/include/libbson-1.0 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

lua-mongoc-database.c c_wrapper/lua-mongoc-database.c(124) : warning C4090: '=' : different 'const' qualifiers cl /MD /O2 -c -Foc_wrapper/lua-mongoc-collection.obj -IC:/Program Files (x86)/Lua/5.1/include c_wrapper/lua-mongoc-collection.c -IC:/libmongoc/include/libmongoc-1.0 -IC:/libmongoc/include/libbson-1.0 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.

lua-mongoc-collection.c c_wrapper/lua-mongoc-collection.c(213) : warning C4090: 'function' : different 'const' qualifiers c_wrapper/lua-mongoc-collection.c(398) : error C2143: syntax error : missing ';' before 'type' c_wrapper/lua-mongoc-collection.c(399) : error C2065: 'num_elements' : undeclared identifier c_wrapper/lua-mongoc-collection.c(399) : error C2065: 'lua_index' : undeclared identifier c_wrapper/lua-mongoc-collection.c(401) : error C2065: 'num_elements' : undeclared identifier c_wrapper/lua-mongoc-collection.c(401) : error C2065: 'lua_index' : undeclared identifier c_wrapper/lua-mongoc-collection.c(404) : error C2065: 'lua_index' : undeclared identifier c_wrapper/lua-mongoc-collection.c(426) : error C2065: 'num_elements' : undeclared identifier Updating manifest for C:\Program Files (x86)\Lua\5.1\rocks

Built the libmongoc and libbson environments using CMake for Windows. mongorover version: 0.1-1 Lua Version: 5.1.4 All Build Tools Utilized are 32-Bit CMake Version: v3.7 Visual Studio VC Environment: VS2010 (v10.0)

Any suggestions as to how this can be resolved so that I can install the mongorover rock correctly?

Thanks;

TD

christopherjwang commented 7 years ago

Thanks for all the information. It makes my job a lot easier.

You found a long standing bug... lua_checkstack doesn't return a char *... That probably isn't even used, and is removed in master.

The other errors are because I declared variables after assigning others here.

Luckily these aren't cryptic errors and are pretty easy to fix :). I think it's because VS has stricter c syntax rules, which I should probably follow..

Are you comfortable trying to install from source? Could you try that and give me an error log? A lot has changed since the first release... I can try and flush it out in master. We should update the luarock and the docs shortly after. That's on me for being a bit too complacent. I will try and get it running on my windows box so I can help you out. Hopefully it isn't as painful as last time...

TDycks commented 7 years ago

Thanks Christopher for the quick response;

This is a bit of an experiment for me as I am looking to use a scripting language other than Python for accessing MongoDB.  Love the clean and simple syntax that Lua offers.  I'm a bit of a "newbie" with C Programming, but I've built a few other products from source on my Centos Linux box and on this Win10 box using Cygwin, so I will give that a try after reading up on Windows source installs.  More to follow after some research.  Best Regards; TD

TDycks commented 7 years ago

One follow-up question RE: Mongo C Driver Version's. I installed C Driver Version 1.3.5 to match the version of the C Driver on my CentOs 6.7 box. Does building the current source for mongorover require a newer version of the Mongo C Driver? I am hoping to use mongorover on both the 2.6 and 3.2 versions of Mongo DB that I having installed on this Windows PC.

Thanks; TD

TDycks commented 7 years ago

Disregard this post, I managed to resolve this by using the -G switch to Specify the Version of Visual Studio to Use. Thanks; TD

Here's the attempt to run CMake while trying to point to my Visual Studio 2010 Environment:

C:\Storage\lua\builds>"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" Setting environment for using Microsoft Visual Studio 2010 x86 tools.

C:\Storage\lua\builds\mongorover-master\build>cmake .. -- Building for: Visual Studio 14 2015 -- The C compiler identification is unknown CMake Error at CMakeLists.txt:3 (project): No CMAKE_C_COMPILER could be found.

-- Configuring incomplete, errors occurred! See also "C:/Storage/lua/builds/mongorover-master/build/CMakeFiles/CMakeOutput.log". See also "C:/Storage/lua/builds/mongorover-master/build/CMakeFiles/CMakeError.log".

I installed the Windows SDK 8.1 as well as a previous cmake attempt complained about that missing. I was hoping to use VS 2010 as that matches the VC environment I used to build the libmongo and libbson libraries. I'm wondering if the mix of the environment is creating some confusion between the CMake Utility and the Visual C Environment used for the build? Can I configure CMake to point to my installation of VS 2010 VC Compiler?

I've attached the following 4 build-related files for your reference:

CMakeLists.txt CMakeError.log.txt CMakeOutput.log.txt

CMakeCache.txt Let me know if I need to provide any additional information to facilitate?

Thanks and Best Regards; TD

TDycks commented 7 years ago

Learned that using the -G switch allows me to specify which version of Visual Studio's VC Environment. So I now have the following pkgconfig fine issue linking in the previously built libmongoc library when using the following CMake command:

C:\Storage\lua\builds\mongorover-master\build>cmake -G "Visual Studio 10 2010" .. -- The C compiler identification is MSVC 16.0.40219.1 -- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe -- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Found Lua: C:/Program Files (x86)/Lua/5.1/lib/lua51.lib (found version "5.1.4") -- Found PkgConfig: C:/Program Files (x86)/CMake/bin/pkg-config.exe (found version "0.28") -- Checking for module 'libmongoc-1.0' -- No package 'libmongoc-1.0' found CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.7/Modules/FindPkgConfig.cmake:415 (message): A required package was not found Call Stack (most recent call first): C:/Program Files (x86)/CMake/share/cmake-3.7/Modules/FindPkgConfig.cmake:588 (_pkg_check_modules_internal) CMakeLists.txt:25 (pkg_check_modules)

-- Configuring incomplete, errors occurred! See also "C:/Storage/lua/builds/mongorover-master/build/CMakeFiles/CMakeOutput.log".

Attachments: CMakeCache.txt CMakeOutput.log.txt CMakeLists.txt

Adding a Directory Listing Attachment of the libmongoc and libbson Libraries previously built with CMake:

libmongoc-dir.txt

christopherjwang commented 7 years ago

Thanks for the info. I'm still in the process of getting my windows box setup. I've installed VS 2010, and will try to get that up and running for you. To build libbson and libmongoc I'm assuming you installed visual studio 2010, cmake, and some type of openssl library. Am I missing anything there? I've never really built anything on Windows, so I have some research and setup required here.

Does building the current source for mongorover require a newer version of the Mongo C Driver?

No, it was initially developed when the 1.2.0 C driver was in beta, and that was a year ago. From what I can tell there shouldn't be any problem using a newer driver.

I am hoping to use mongorover on both the 2.6 and 3.2 versions of Mongo DB that I having installed on this Windows PC.

Usually most all mongo drivers can talk to all versions of the MongoDB databases. You don't really have to worry about that. This driver is bare-bones and simple enough that it probably doesn't even expose some of the deprecated functionality.

christopherjwang commented 7 years ago

@TDycks Did you install the c driver on windows with ssl? I'm having issues finding sources / compiling libsasl2.

TDycks commented 7 years ago

Hello Christopher;

It appears that I did. Similar finding no libsasl2 modules built. These are the steps I took to build the Mongo C Driver (Bolded the CMake Command where I attempted to enable SSL):

git clone https://github.com/mongodb/mongo-c-driver.git cd mongo-c-driver git checkout 1.3.5 # for your specific release git submodule init git submodule update # libbson is a submodule cd src\libbson cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -G "Visual Studio 10 2010" . msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj cd ..\ .. cmake -DCMAKE_INSTALL_PREFIX=C:\libmongoc -DENABLE_SSL=WINDOWS -DBSON_ROOT_DIR=C:\libmongoc -G "Visual Studio 10 2010" . msbuild.exe ALL_BUILD.vcxproj msbuild.exe INSTALL.vcxproj

I do not have a SSL Client or Server Module installed on my laptop computer as this is just a standalone Mongo environment for taking courses and learning how to develop in it. Do you have a suggestion for a OpenSSL Module that I can install on this laptop to meet the requirements and build the libasasl2 module? I did not realize this was a pre-requisite for the Mongo C Driver. Don't recall whether it was a requirement for the Python MongoDB "pymongo" Driver that I used for the Mongo DB University course?

Thanks for the follow-up; If you can suggest some Windows 10 friendly version of SSL to install, I can retry the build of the driver? Best Regards; TD

christopherjwang commented 7 years ago

Alright, I'm finally up and running on a windows box and have the issues that you've run into in your initial issue. Sorry for the delays. This has been quite the journey.

We are trying to install the older c driver 1.3.5 with the newer instructions 1.5.0. In the documentation, it mentions that they now have native windows SSL. Since it won't be much help if it doesn't work, I'll probably refrain from having you retrace my steps until I have something up and running.

christopherjwang commented 7 years ago

https://github.com/mongodb-labs/mongorover/tree/christopherjwang/windows_compiling

I have it compiling and running :tada: (but without authentication). I only have VS 2010 installed and the Windows SDK 7.1.

working_no_auth_mongorover_windows

I believe all I need to do now is compile the C driver with SSL included. I'll make a write up for you tomorrow. Sound good?

TDycks commented 7 years ago

Hi Christopher; sounds great! Look forward to your write-up. If I get the driver working on my Windows 10 laptop, I will try to set it up on my Windows 7 PC as well and will report on my findings. Thanks for your efforts. TD

christopherjwang commented 7 years ago

Okay, steps I took to do this:

  1. Installed Windows 7 on a fresh box
  2. Installed Visual Studio Express 2010. I found the .iso here, as VS Express has now become Visual Studio Community and Community is apparently slightly different.
  3. Installed Windows SDK v7.1 3a. I have no idea if this is actually necessary, because I initially got it for building 64 bit stuff. Since Lua is 32 bit, you probably won't need this, but I included it in these steps just in case
  4. Install the SP1 Update for Visual Studio 2010. Thanks @TDycks for the missing step (see below)!
  5. I built OpenSSL: 5a. Roughly followed this guide, even though it is very out of date 5aa. Install ActivePerl 5ab. Download OpenSSL source code. I downloaded openssl-1.1.0c.tar.gz. I unzipped this straight to my C:\ drive. 5ac. Install NASM. I installed the x64 2.12.02 version 5ad. I installed with these commands. I mostly used all the tutorial's paths. The tutorial is out of date with making with nmake, so here are updated instructions.
    cd C:\openssl-src-32
    perl Configure VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32
    nmake
    nmake test
    nmake install
  6. I was unable to install libmongoc v1.3.5 with openssl. I instead used the latest version v1.5.0. If this is a problem (which I don't think it should), let me know. There is a small distinction in both cmake commands between what I did and what is in the libmongoc install instructions. You want to build for 32 bit for both, and in libmongoc, enable SSL but disable SASL. SASL is used for Kerberos and LDAP, do you need that? I'm going to assume you don't need Kerberos or LDAP.
    cd mongo-c-driver-1.5.0
    cd src\libbson
    cmake -DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver -G "Visual Studio 10"
    msbuild.exe ALL_BUILD.vcxproj
    msbuild.exe INSTALL.vcxproj
    cd ..\..
    cmake -DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver -DBSON_ROOT_DIR=C:\mongo-c-driver -DENABLE_SSL=WINDOWS -DOPENSSL_ROOT_DIR=C:\Build-OpenSSL-VC-32 -DENABLE_SASL:BOOL=OFF -G "Visual Studio 10"
    msbuild.exe ALL_BUILD.vcxproj
    msbuild.exe INSTALL.vcxproj

    Since you already have luarocks, I'm assuming that you don't need help with that. The last thing I had to do was include C:\mongo-c-driver\bin to my Windows PATH variable.

Then you can clone mongorover and run (as Administrator):

luarocks make mongorover-0.1-1.rockspec LIBBSON_DIR=C:\mongo-c-driver LIBMONGOC_DIR=C:\mongo-c-driver

I've merged in the changes in #76, so just compile from master.

Other problems I ran into while doing this:

  1. Installing Github for Windows installs the .Net Framework v4.5. Having this conflicted with the .Net framework for Visual Studio Express 2010, causing errors with compiling OpenSSL.
  2. I had a space in my PATH variable, which really messes everything up.
  3. If you do not add the path to libmongoc-1.0.dll in your PATH or do not set it up correctly, running require('mongorover') will error out with a windows error saying that the dll is missing and needs to be installed.

Tests pass, so you should be good to go! working_mongorover

TDycks commented 7 years ago

Thanks Christopher; I have a Win7 Pro x64 Laptop as well; so I will use the detailed steps you provided above to build the Mongo C Driver and Lua mongorover module, since that matches your Win build environment. Will report on findings. Best Regards; TD

TDycks commented 7 years ago

Hi Christopher; Following the detailed steps you provided on my Windows 7 x64 laptop, I now have built the mongorover-0.1.1 using the mongo-c-driver-1.5.0 version driver. One additional detail for the sake of anyone installing the Visual Studio 2010 VC++ Environment and are using multiple newer versions of Visual Studio C++ Environment (I had VS 2013 installed as well) :

Install the SP1 Update for Visual Studio 2010 (VS10sp1-KB983509.exe for the Windows 7 64-bit OS). URL: https://www.microsoft.com/en-us/download/details.aspx?id=23691 This was a requirement in order to run the nmake successfully for the build of the OpenSSL source.

christopherjwang commented 7 years ago

That's good to hear. Let me know if you run into any more issues. If you do try it on Windows 10, will you let me know your results?

Thanks for the extra step, I'll update the instructions. Edit: they've been updated

TDycks commented 7 years ago

From the Lua Interpreter, I am able to successfully run the following require commands after firing up the Mongod.exe Daemon from my Mongo 2.6 installation ...

C:\Storage\lua\rocks\mongorover-master\test>lua Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

require "luaunit" require 'luaHelperFunctions' local mc = require("mongorover.MongoClient")

However, when I attempt the require of 'TestClient', I get the following errors ...

C:\Storage\lua\rocks\mongorover-master\test>lua Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

require 'TestClient' TestClient

BUG: cluster: Authentication failed: auth failed 2016/12/15 16:07:12.0516: [14032]: DEBUG: cluster: Authentication failed : auth failed Failed 2016/12/15 16:07:13.0019: [14032]: DEBUG: cluster: Authentication failed : auth failed [TestClient:test_client_call_metamethod] 2016/12/15 16:07:13.0030: [14032]: DEBUG: cluster: Authentication failed: auth failed 2016/12/15 16:07:13.0532: [14032]: DEBUG: cluster: Authentication failed : auth failed Failed 2016/12/15 16:07:14.0035: [14032]: DEBUG: cluster: Authentication failed : auth failed [TestClient:test_client_index_into_database] 2016/12/15 16:07:14.0046: [14032] : DEBUG: cluster: Authentication failed: auth failed Failed 2016/12/15 16:07:14.0550: [14032]: DEBUG: cluster: Authentication failed : auth failed [TestClient:test_client_no_authentication] 2016/12/15 16:07:14.0555: [14032]: DEBUG: cluster: Authentication failed: auth failed Failed 2016/12/15 16:07:15.0059: [14032]: DEBUG: cluster: Authentication failed : auth failed [TestClient:test_no_gc_until_database_gc] 2016/12/15 16:07:15.0062: [14032]: DEBUG: cluster: Authentication failed: auth failed Failed 2016/12/15 16:07:15.0565: [14032]: DEBUG: cluster: Authentication failed : auth failed

Failed tests:

TestClient:test_client_authenticate failed ...m Files (x86)\Lua\5.1\lua\mongorover\MongoClient.lua:61: auth failed stack traceback: C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:454: in function <C:\Prog ram Files (x86)\Lua\5.1\lua\luaunit.lua:453> C: in function 'client_get_database_names' ...m Files (x86)\Lua\5.1\lua\mongorover\MongoClient.lua:61: in function 'getDatabaseNames' .\TestClient.lua:31: in function 'test_client_authenticate' [string "TestClient:test_client_authenticate()"]:1: in main chunk C: in function 'xpcall' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:458: in function 'runTest Method' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:479: in function 'runTest MethodName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:508: in function 'runTest ClassByName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:542: in function 'run' .\TestClient.lua:89: in main chunk C: in function 'require' stdin:1: in main chunk

TestClient:test_client_call_metamethod failed ...m Files (x86)\Lua\5.1\lua\mongorover\MongoClient.lua:61: auth failed stack traceback: C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:454: in function <C:\Prog ram Files (x86)\Lua\5.1\lua\luaunit.lua:453> C: in function 'client_get_database_names' ...m Files (x86)\Lua\5.1\lua\mongorover\MongoClient.lua:61: in function 'getDatabaseNames' .\TestClient.lua:38: in function 'test_client_call_metamethod' [string "TestClient:test_client_call_metamethod()"]:1: in main chunk C: in function 'xpcall' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:458: in function 'runTest Method' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:479: in function 'runTest MethodName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:508: in function 'runTest ClassByName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:542: in function 'run' .\TestClient.lua:89: in main chunk C: in function 'require' stdin:1: in main chunk

TestClient:test_client_index_into_database failed .\TestClient.lua:57: attempt to call field 'assertEquals' (a nil value) stack traceback: C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:454: in function 'assertE quals' .\TestClient.lua:57: in function 'test_client_index_into_database' [string "TestClient:test_client_index_into_database(..."]:1: in main chu nk C: in function 'xpcall' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:458: in function 'runTest Method' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:479: in function 'runTest MethodName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:508: in function 'runTest ClassByName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:542: in function 'run' .\TestClient.lua:89: in main chunk C: in function 'require' stdin:1: in main chunk

TestClient:test_client_no_authentication failed .\TestClient.lua:78: attempt to call field 'assertErrorMsgContains' (a nil value ) stack traceback: C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:454: in function 'assertE rrorMsgContains' .\TestClient.lua:78: in function 'test_client_no_authentication' [string "TestClient:test_client_no_authentication()"]:1: in main chunk C: in function 'xpcall' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:458: in function 'runTest Method' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:479: in function 'runTest MethodName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:508: in function 'runTest ClassByName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:542: in function 'run' .\TestClient.lua:89: in main chunk C: in function 'require' stdin:1: in main chunk

TestClient:test_no_gc_until_database_gc failed .\TestClient.lua:86: attempt to call field 'assertNotNil' (a nil value) stack traceback: C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:454: in function 'assertN otNil' .\TestClient.lua:86: in function 'test_no_gc_until_database_gc' [string "TestClient:test_no_gc_until_database_gc()"]:1: in main chunk C: in function 'xpcall' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:458: in function 'runTest Method' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:479: in function 'runTest MethodName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:508: in function 'runTest ClassByName' C:\Program Files (x86)\Lua\5.1\lua\luaunit.lua:542: in function 'run' .\TestClient.lua:89: in main chunk C: in function 'require' stdin:1: in main chunk

Success : 0% - 0 / 5

christopherjwang commented 7 years ago

are you running mongod with auth?

You also need to set up a user and password. Instructions in readme

TDycks commented 7 years ago

Thanks Christopher; Nope; was running Mongo sans the security configuration, Forgot about the .pem file setup for SSH. My apologies. Appreciate all your effort and tutorials on this. Just tested the find program in the examples and things are working A-Okay. On to the Windows 10 configuration. Many Thanks. TD

christopherjwang commented 7 years ago

Glad I could help. Thanks for bringing up the issue. Best of luck with whatever you're building!