Compile from source C# generates a DLL specified AnyCPU but is in fact x86

613 views
Skip to first unread message

Sean Creighton

unread,
Oct 6, 2016, 7:54:19 AM10/6/16
to or-tools-discuss
Here is ILspy's view of the dll, as a result of the make csharp command


however it is only x86 compatible:

running with a platform target of x64, gives this




Mark Farkas

unread,
Oct 6, 2016, 8:02:06 AM10/6/16
to or-tools...@googlegroups.com
Hey Sean!

Make sure you set the environment variables of VS2015 for the AMD64 architecture using:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

You have to rebuild the c++ library and csharp wrappers as well using make cc and make csharp.
Hope that helps.

Cheers,
Mark

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Creighton

unread,
Oct 6, 2016, 8:35:33 AM10/6/16
to or-tools-discuss
Hi Mark

I'm after an AnyCPU build. However I can see that that this is a C# wrapper on top of C++ code that must be doing a PInvoke somewhere.

I think I would need to figure out how to create something like this 


This suggested soln here, seems like it will work. I will just need to get to grips with the ortools library design to implement it.

Ideally this would live in the C# wrapper of or-tools, where it interacts/loads c++.  So I would have two C++ dlls, x86 and x64.


Else I will have to do it higher up at the .Net level, which actually looks, surprisingly, more complicated.


Either way this seems like a bug that it write AnyCPU in the manifest.

Thanks
Sean

















On Thursday, 6 October 2016 14:02:06 UTC+2, farka...@gmail.com wrote:
Hey Sean!

Make sure you set the environment variables of VS2015 for the AMD64 architecture using:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

You have to rebuild the c++ library and csharp wrappers as well using make cc and make csharp.
Hope that helps.

Cheers,
Mark
On Thu, Oct 6, 2016 at 1:54 PM, Sean Creighton <sean.cr...@gmail.com> wrote:
Here is ILspy's view of the dll, as a result of the make csharp command


however it is only x86 compatible:

running with a platform target of x64, gives this




--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

Sean Creighton

unread,
Nov 22, 2016, 12:02:29 PM11/22/16
to or-tools-discuss

   "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

followed by

   make cc

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\utility(123): warning C4244: 'initializing': conversion from 'const int64' to 'int', possible loss of data
src\base/hash.h(393): note: see reference to function template instantiation 'std::pair<int,int>::pair<int64,int64,void,0>(const std::pair<int64,int64> &)' being compiled
src\base/hash.h(393): note: see reference to function template instantiation 'std::pair<int,int>::pair<int64,int64,void,0>(const std::pair<int64,int64> &)' being compiled
c:\_code\cshrp\or-tools\src\constraint_solver\expressions.cc(4922) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 255)
 To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information

INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe'
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
tools\make: *** [objs/constraint_solver/expressions.obj] Error 1

just me?







On Thursday, 6 October 2016 13:02:06 UTC+1, farka...@gmail.com wrote:
Hey Sean!

Make sure you set the environment variables of VS2015 for the AMD64 architecture using:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

You have to rebuild the c++ library and csharp wrappers as well using make cc and make csharp.
Hope that helps.

Cheers,
Mark
On Thu, Oct 6, 2016 at 1:54 PM, Sean Creighton <sean.cr...@gmail.com> wrote:
Here is ILspy's view of the dll, as a result of the make csharp command


however it is only x86 compatible:

running with a platform target of x64, gives this




--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

cm2...@googlemail.com

unread,
Mar 1, 2017, 7:05:31 PM3/1/17
to or-tools-discuss
Hi Sean

did you find a solution to the int64 to int error? I am getting exactly the same

Best regards
Charles

Laurent Perron

unread,
Mar 2, 2017, 2:28:31 AM3/2/17
to or-tools-discuss
int64 error. This is a compiler bug. I do not know why I cannot reproduce it on my machine, maybe a different patch level.
As a workaround, I would compile the file will less optimization

I believe the command line would be:
tools\make objs/constraint_solver/expressions.obj DEBUG="/O1"

and then resume compilation.

--

Laurent Perron

unread,
Mar 2, 2017, 2:31:24 AM3/2/17
to or-tools-discuss
About AnyCPU, this is just too complex for us to undertake. The solution seems fragile at best.
And I do not believe we should build for 32 bit anymore. So I am not inclined to go down that part.

cm2...@googlemail.com

unread,
Mar 2, 2017, 4:46:01 AM3/2/17
to or-tools-discuss
Hi Laurent

re reproducing it, I just set up a clean VM, and followed the step below, and get the same error. I would be happy to give you access to that VM so you can observe the problem yourself.

Steps:
Installed VS 2015 Community Update 3, selected C++, Git as install options
Installed subversion
Installed cmake x64 version from installer, checked add cmake to path variables
Unzipped the or-tools-master from github
Added the or-tools-master\tools directory to the Path variable of the current user
Opened VS2015 x64 Native Tools Command Prompt
Navigated to or-tools-master directory, entered the following commands:
git init
make third_party
make csharp

Regarding the workaround you suggest, I'm afraid I am a bit outside of my area of confidence when compiling c++. In which file should I change this?


Govert Versluis

unread,
Mar 2, 2017, 4:52:26 AM3/2/17
to or-tools-discuss
It might be worth noting I've experienced a very similar (if not the same) internal compiler error when compiling on my machine with very similar components installed, albeit Visual Studio Professional 2015 Update 3. Disabling optimizations made the error go away.

If there's any way I can assist in debugging, I would be happy to.

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.

cm2...@googlemail.com

unread,
Mar 2, 2017, 4:57:11 AM3/2/17
to or-tools-discuss
I would welcome any help I can get. Wouldn't disabling compiler optimization significantly impact the performance of the solver?

cm2...@googlemail.com

unread,
Mar 2, 2017, 3:41:45 PM3/2/17
to or-tools-discuss
I should have thought about it earlier but I finally found the solution: simply use Visual Studio 2013 Community Edition Update 4. It still throws some errors on the current github source code but works fine on v5.1. I could even compile with GLPK and SCIP successfully.

A complete step by step in case on a clean VM someone else as inexperienced as me attempts it.

1. Install VS 2013 Community Update 4

2. Install subversion

3. Install git

4. Install 7 zip

5. Install cmake x64 version from installer, checked add cmake to path variables

6. Unzip the or-tools version 5.1

7. Add the or-tools-master\tools directory to the Path variable of the current user

8. Edit makefiles\Makefile.third_party.win, comment out the following two lines:
# git checkout dependencies/solutions/Scip/soplex/soplex.vcxproj
# git checkout dependencies/solutions/Scip/scip/scip.vcxproj
and add "--no-check-certificate" to the following line:
tools\wget -P dependencies\archives --no-check-certificate https://sourceforge.net/projects/winflexbison/files/win_flex_bison-$(BISON_FLEX_TAG).zip
9. Download the versions of GLPK and SCIP that are referenced in the file makefiles\Makefile.third_party.win at the top, in my case:

10 For scipoptsuite-3.2.0.tgz, extract it with 7zip, then recreate an archive with 7zip, select tar as format. When down change the extension from .tar to .tgz

11. Put both GLPK and SCIP into dependencies\archives

12. Opened VS2013 x64 Native Tools Command Prompt

13. Navigated to or-tools-master directory, entered the following commands:
git init
make third_party
make csharp

That compiles a x64 version successfully for me.

cm2...@googlemail.com

unread,
Mar 3, 2017, 2:16:55 PM3/3/17
to or-tools-discuss
Correction: the second line to replace in make third_party is:

tools\wget -P dependencies\archives --no-check-certificate http://prdownloads.sourceforge.net/swig/swigwin-$(SWIG_TAG).zip || (@echo wget failed to dowload http://prdownloads.sourceforge.net/swig/swigwin-$(SWIG_TAG).zip, try running 'tools\wget -P dependencies\archives --no-check-certificate http://prdownloads.sourceforge.net/swig/swigwin-$(SWIG_TAG).zip' then rerun 'make third_party' && exit 1)

Michael Powell

unread,
Mar 4, 2017, 2:29:43 AM3/4/17
to or-tools-discuss


On Tuesday, November 22, 2016 at 12:02:29 PM UTC-5, Sean Creighton wrote:

   "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

You should be running from the VS developer command prompt as far as I can tell. Not sure what effect including or excluding the amd64 from the vars has, however.

followed by

   make cc

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\utility(123): warning C4244: 'initializing': conversion from 'const int64' to 'int', possible loss of data
src\base/hash.h(393): note: see reference to function template instantiation 'std::pair<int,int>::pair<int64,int64,void,0>(const std::pair<int64,int64> &)' being compiled
src\base/hash.h(393): note: see reference to function template instantiation 'std::pair<int,int>::pair<int64,int64,void,0>(const std::pair<int64,int64> &)' being compiled
c:\_code\cshrp\or-tools\src\constraint_solver\expressions.cc(4922) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 255)
 To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information

I don't know that I have encountered this one, yet. Not to say that I wouldn't, yet. 

If you're spending any time at all with this one, perhaps you'd like to touch base with me offline. I'm looking into the AssemblyInfo issue.

Possible having to do with the MODULE intermediate output to LINK. That, or find a way to just output the CSC to DLL directly.

As an alternate approach, considering whether a CSPROJ would work instead, with sufficient auto generated code backing it up. Baseline CSC to LINK should work first, then see whether/how to build a CSPROJ. The trick there I imagine would be how to reference the system DLLs and especially OBJ files and/or a linked intermediate LIB.

I'd also like to have a local Nuget pipeline and/or determine why we haven't seen a Nuget package in some time.

Commits and PR to follow perhaps this weekend at the earliest.

Let me know.

Michael Powell

unread,
Mar 4, 2017, 2:30:07 AM3/4/17
to or-tools-discuss


On Thursday, March 2, 2017 at 2:31:24 AM UTC-5, Laurent Perron wrote:
About AnyCPU, this is just too complex for us to undertake. The solution seems fragile at best.
And I do not believe we should build for 32 bit anymore. So I am not inclined to go down that part.

Good to know. Thanks for the insight.
Reply all
Reply to author
Forward
0 new messages