CerebusOSS/CereLink

Compilation with Visual Studio 2013

Closed this issue · 19 comments

Hi
I am looking for a python interface to the Cerebus system.
I have tried to compile Cerelink with Visual Studio 2013/Windows 7, and it failed. Here are the steps:
In the Visual Studio command line:

cmake .

which adds a lot of vcxproj files to the build folder.

The wiki then advises to run make all and make install, but this step does not work with the generated vcxproj files, so I followed the Visual Studio route, and run MSBUILD ALL_BUILD.vcxproj

This step fails, with the following error:

"C:\Users\master\Documents\CereLink-master\build\ALL_BUILD.vcxproj" (cible par
défaut) (1) ->
"C:\Users\master\Documents\CereLink-master\build\cbpy.vcxproj" (cible par défau
t) (3) ->
"C:\Users\master\Documents\CereLink-master\build\cbsdk_static.vcxproj" (cible p
ar défaut) (4) ->
(Lib cible) ->
LINK : warning LNK4068: /MACHINE not specified; defaulting to X86 [C:\Users\m
aster\Documents\CereLink-master\build\cbsdk_static.vcxproj]

"C:\Users\master\Documents\CereLink-master\build\ALL_BUILD.vcxproj" (cible par
défaut) (1) ->
"C:\Users\master\Documents\CereLink-master\build\cbpy.vcxproj" (cible par défau
t) (3) ->
(Link cible) ->
LINK : fatal error LNK1104: cannot open file 'C:\Users\master\Documents\CereL
ink-master\dist\lib\Debug..\cbsdk_staticd.lib' [C:\Users\master\Documents\Cere
Link-master\build\cbpy.vcxproj]

Do you know if this can be solved our would you advise to rather move to Linux ? (I want the same machine to host both Cerelink and the Cerebus standard GUI)

Thanks a lot for your help
Luc Estebanez
^^^^^^^^^^^^^^^^^^
Post-doctoral researcher,
CNRS, France

The visual studio build project may not work with other than exact version (never tested), but now we have a portable way to compile on different platforms using CMake. After you install CMake, open a Visual Studio 2013 Command Prompt (usually an option addd in command prompt, but also accessible through visual studio tools menu also), and the rest is like any CMake. Navigate to build do a cmake then make.

Thanks so much for your guidance. I thought I followed these steps, but I will try again back in the lab on Monday, and I will let you know the outcome...

All the best,
Luc

@lucestebanez I think I have to test this myself too, it has been some time I did not test with VS, and I can only test 2008 because that is free. Will test this weekend.

Thanks so much for that ! Actually I made the mistake of assuming that Visual Studio Express 2013 may have been sufficient to compile the code. If you coud test and maybe write down the steps for the Visual Studio 2008 procedure, I would then download Visual Studio 2008 and follow your steps carefully !

Best wishes,
Luc

Ok I got Qt4 from here and am trying this in a XP VM in VS2008. After cmake . step, I opened the sln and tried to build, and yes I get error about lack of afxres.h which is some reminiscent of the time I had VS license and thus MFC. This is only for compiling the icon into binary, which is not that critical anyways, I will try to find a workaround and update you here.

Ok, in this commit fixed the build now I can open sln and build all. Please note that I took cbpy out of CMake build because the cbpy version in cerebus which is written in Cython is better tested, even though it does not have all the functionalities, most important ones are there. To get that cbpy after cbsdk_static is built and installed you can use setup.py to build the cbpy, I think the docs need update, so PR is welcome. Also let me know if it works in VS2013 now, even though the error in that case seems like the CMake build cannot produce correct sln from dependencies.

Thanks a lot. I could succesfully build the package this time using Visual Studio Community edition 2013. However, the install failed because the file names in the cmake_install.cmake file were somehow wrong (there were /../ inserted in the paths).
After correcting this, I now have in C:\Program Files (x86)\CBSDK the following folder tree:

CBSDK

bin
> cbsdkd.dll
> testcbsdk
include
> cbhwlib.h
> cbsdk.h
lib
> cbsdk_staticd.lib
> cbsdkd.lib

Also, I ran in a command line testcbsdk.exe and I got the following (with my cerebus online):

C:\Program Files (x86)\CBSDK\bin>testcbsdk.exe
Initializing Cerebus real-time interface 6.04.00.00 (protocol cb3.09)...
Udp real-time interface to NSP (6.04.00.00) successfully initialized
testOpen succeeded
Interface closed successfully
testClose succeeded

So things look good there.
But then I tried to compile what I am interested in, which is the python interface, by running on a command line (Annaconda installed) the setup.py:

C:\Users\master\Documents\CereLink-master>python setup.py install
running install
running bdist_egg
running egg_info
writing cerelink.egg-info\PKG-INFO
writing top-level names to cerelink.egg-info\top_level.txt
writing dependency_links to cerelink.egg-info\dependency_links.txt
reading manifest file 'cerelink.egg-info\SOURCES.txt'
writing manifest file 'cerelink.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
skipping 'cerebus\cbpyw.cpp' Cython extension (up-to-date)
building 'cerebus.cbpy' extension
C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\lib\site-pac
kages\numpy\core\include -IC:\Anaconda\include -IC:\Anaconda\PC -c cerebus\cbpyw
.cpp -o build\temp.win-amd64-2.7\Release\cerebus\cbpyw.o
In file included from cerebus\cbpyw.cpp:230:0:
cerebus\cbpy.h:13:19: fatal error: cbsdk.h: No such file or directory
compilation terminated.
error: command 'C:\Anaconda\Scripts\gcc.bat' failed with exit status 1

It looks like the compiler cannot find the header files corresponding to the cbsdk library. I tried my luck and directly copied the missing .h files into the /cerebus directory, but this leads to other errors that are probably due to the need for other files than just the .h files...
I also tried to add the library to the PATH variable without success.

Thanks a lot for any advice you may have to finish this last step!
All the best,
Luc

Yes you are right, this is Windows, will get back to this soon

Hi Ehsan,

Just to tell you that I really look forward to your kind help, and if needed I would definitely try things on my system to debug the situation.

All the best,
Luc

setup.py does compile now (python setup.py build_ext, python setup.py install,...), will look at usual locations for static library (make sure to compile a Release version first), it also tries to find Qt install location reading the registry, but if QTDIR environment variable is set (export QTDIR=blahblah) it will be used instead. If Cython is installed it will rebuild the intermediate cpp file, otherwise it uses the one in the repo, I will have to make sure I keep it updated if anything changes.

Thanks a lot for these fix Ehsan.

Sadly, somehow things still don't work at the 'buid extension' stage. Basically, after I have compiled a Release version of the bpackage, I went to the ./CereLink-master level, and there I run python setup.py build_ext. The first lines of output are the following:

C:\Users\master\Documents\CereLink-master>python setup.py build_ext
running build_ext
skipping 'cerebus\cbpyw.cpp' Cython extension (up-to-date)
building 'cerebus.cbpy' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\cerebus
C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\lib\site-packages\numpy> \core\include -IC:\Users\master\Documents\CereLink-master\dist\include -IC:\Qt\4.8.6\include -IC:\Users\master\Documents\CereLink-master\compat -IC:\Anaconda\include -IC:\Anaconda\PC -c cerebus\cbpyw.cpp -o build\temp.win-amd64-2.7\Release\cerebus\cbpyw.o
In file included from c:\anaconda\mingw\bin../lib/gcc/x86_64-w64-mingw32/4.7.0/include/stddef.h:1:0,
from C:\Users\master\Documents\CereLink-master\compat/stdint.h:187,
from C:\Users\master\Documents\CereLink-master\compat/stdint.h:197,
from C:\Users\master\Documents\CereLink-master\compat/stdint.h:197,
from C:\Users\master\Documents\CereLink-master\compat/stdint.h:197,
from C:\Users\master\Documents\CereLink-master\compat/stdint.h:197,

The last lines are:

cerebus\cbpyw.cpp:1485:13: warning: 'void _pyx_insert_code_object(int, PyCodeObject)' declared 'static' but never defined [-Wunused-function]
cerebus\cbpyw.cpp:1487:13: warning: 'void Pyx_AddTraceback(const char, int, int, const char)' declared 'static' but never defined [-Wunused-function]
cerebus\cbpyw.cpp:1490:12: warning: 'int __Pyx_InitStrings(_Pyx_StringTabEntry)' declared 'static' but never defined [-Wunused-function]
cerebus\cbpyw.cpp:9093:32: warning: 'pyx_array_obj* pyx_array_new(PyObject, Py_ssize_t, char, char, char)' defined but not used [-Wunused-function]
cerebus\cbpyw.cpp:12775:18: warning: 'PyObject* _pyx_memoryview_new(PyObject, int, int, _Pyx_TypeInfo)' defined but not used [-Wunused-function]
cerebus\cbpyw.cpp:1568:23: warning: '__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t' defined but not used [-Wunused-variable]
cerebus\cbpyw.cpp:1569:23: warning: '__Pyx_TypeInfo_nn___pyx_t_5numpy_uint32_t' defined but not used [-Wunused-variable]
cerebus\cbpyw.cpp:1570:23: warning: '__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t' defined but not used [-Wunused-variable]
cerebus\cbpyw.cpp:1571:23: warning: '__Pyx_TypeInfo_nn___pyx_t_5numpy_int16_t' defined but not used [-Wunused-variable]
error: command 'C:\Anaconda\Scripts\gcc.bat' failed with exit status 1

I will try to get some local support to solve this issue, but obviously if you have any idea of what is going on, I would be happy to have your help... I will make sure to write down the correct steps in the wiki one this issue is solved.

All the best,
Luc

Can you try the setup.py approach from within the Visual Studio command line? Since most of these libraries are built with VS, it makes sense to stick to it rather than mingwin even if you resolve the build issue you have with mingwin. If it is inside VS command line and still it is trying to use mingwin gcc, then you should look to find how to make sure VS toolchain. It seems the error you get is basically a crash in the build, it is not an error about the actual code, all the logs show is warnings. Another thing, I included stdint because VS2008 does not have it, but mingwin has its own version, you can delete the one in compat and try again with mingwin, again it is usually not a good idea to mix compilers though.

Did you figure out why gcc was used in your case?
Here are the binaries.

Dear Ehsan,

First thanks so much for these binaries. I will test them tomorrow, and for sure they are going to help me tremendously!
Regarding the compilation process, the reason MinG was triggered was that I did not have the correct setup tools (you need >6.0) and I missed also the adequate compiler from microsoft (there is a specific version of the VS 2008 compiler that is distributed specifically to compile python extensions). In the end, I read in several places that for compatibility reasons I should compile python 2.7 extensions with VS 2008. So in the end I installed VS 2008 at the end of last week and I started this morning to work on getting the compilation done... (one additional motivation is that you are successful in building the python module with VS 2008).

All the best,
Luc

Le Lundi, 16 Février, 2015 18:59 CET, Ehsan Azar notifications@github.com a écrit:

Did you figure out why gcc was used in your case?
Here are the binaries.


Reply to this email directly or view it on GitHub:
#44 (comment)

Dear Ehsan,

Thanks a lot again. I could connect to the Cerelink system, and I could have some basic interaction with it. Howevere, I start to understand that the interface does not offer a two-way communication with the hardware, and it is only able to read the stream of experimental data, Am I right ? In case when I need to write to a digital port, how would I accomplish this ? Should I directly write UDP packet using a python UDP library ?

All the best,
Luc

Evrything that can be done by cbsdk (or cbmex) we should be able to do by cbpy, and that includes controlling digital channels,.., even controlling the custom extensions.
However I have not yet implemented all of them, and started with those that someone asked for first. I will add digital channels to it, but this weekend I will not be in town, so it will have to be at least in the weekend afterwards. If you are good in Python you can take a look at cbpyw.pyx to see how it wraps cbsdk, it is actually not hard.

This would be awesome ! I will have a look then, and let you know if I have made progress before the week after...

Best wishes,
Luc

I added the digital output command, here is for Windows. As can be seen in this commit using Cython it is mechanical to add all other commands.

Thanks so much for that! I will test it and try to contribute further as I use the system and have further needs.

Best wishes, Luc