porting network code to 64 bits - sockets

I have a program that performs some network IO that compiles a 32 bit binary just fine
However, when I set the -m64 option at compile time I get the following rather cryptic error
In file included from /usr/include/sys/stream.h:22,
from /usr/include/netinet/in.h:62,
from /usr/include/sys/socket.h:221,
from operation_networkio.cc:15:
/usr/include/sys/vnode.h:241: error: overflow in array dimension
/usr/include/sys/vnode.h:241: error: size of array `pad' is too large
the offending lines in my source code operation_networkio.cc that are triggering this error in my program seem to be
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
could someone enlighten me what I am doing wrong and how to cure this ?
I'm using GCC on Solaris sparc

eventually found that I had -mfaster-structs option enabled on the compilation.
For some reason removing this option cures this build problem. that causes a 64 bit build to fail, though a 32 bit build works.
If someone could explain it I'd certainly like to know why

This is indeed weird.
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/sys/vnode.h#286
It should not be possible that these data structures grow beyond 64 bytes. Or maybe you included some files that redefine these data structures. To be sure what the cause is, you should look at the preprocessed output from the C compiler.
g++ -E operation_networkio.cc -I... -D... -o preprocessed.cc
After running that command you should have a look at the file preprocessed.cc. Search for vn_vfslocks_entry and see if the code around that definition is what you expect.

Related

Compiler generates FPU instructions

I realize a CMSIS Project solution with VS Code but I've an error on an include file :
#include "stm32f10x.h"
And I've got this error :
In included file: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"clang(pp_hash_error)
core_cm3.h(90, 6): Error occurred here
The path of this file is here :
C:\Users\"name"\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.0\Device\Include
But I think I forgot something during the configuration.
I justa want to build my C file but VS code doesn't make the link between my .h and my CMSIS project.
You are never supposed to #include "stm32f10x.h"
You only #include "stm32f1xx.h" and it will include the other headers you need.
You must also define a macro on the command line, one of STM32F101x6, STM32F101xB, STM32F101xE or STM32F101xG.
For most compilers you can define this with an argument like -DSTM32F101xB.
After that you will need particular command line arguments that match your chosen processor, such as -mthumb -mcpu=cortex-m3 -mfpu=none.
Maybe your error was specifying an incorrect -mfpu=.

MATLAB - Error creating maxmaci64 from jpeg_write.c

I had problems making mexmaci64 files using Mex from both jpeg_read.c and jpeg_write.c from jpeg toolbox. I asked my question here and the problem for jpeg_read solved.
but I still have a different error when I compile jpeg_write.c.
everything is the same and I didn't change any path or anything.
I don't understand why Matlab console returns this error.
Is this familiar to anybody? please let me know.
>> mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include jpeg_write.c -L/usr/local/Cellar/jpeg/9d/lib -ljpeg
Building with 'Xcode with Clang'.
Error using mex
/Users/folder/jpeg_toolbox/jpeg_write.c:56:10: fatal error: 'jpegint.h' file not found
#include <jpegint.h>
^~~~~~~~~~~
1 error generated.
First off:
By pointing at the /usr/local/Cellar/jpeg/<version>/include location of the jpeg or other libraries, you're dependent on the specific version that is currently installed. You probably want to use /usr/local/opt/jpeg/include/ etc instead. /usr/local/opt is where Homebrew exposes its non-versioned presentations of its installed package contents.
So:
mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include ...
This is pointing at the jpeg library. Does the jpeg library supply jpegint.h?
$ ls /usr/local/Cellar/jpeg/9d/include/
jconfig.h jerror.h jmorecfg.h jpeglib.h
Nope. So that's why it's not found. So you have to figure out where you can actually get jpegint.h from. Hit Google and consult your documentation to figure out what library you're actually trying to pull jpegint.h from, and pull that in, too, with the appropriate -I, -L, and -l flags.
If you think you have it already installed, you can use find /usr/local/Cellar -name jpegint.h to look for it. I found it in the gdcm package.
[~] $ find /usr/local/Cellar -name jpegint.h
/usr/local/Cellar/gdcm/3.0.8_1/include/gdcm-3.0/gdcmjpeg/jpegint.h
So you probably want something like:
mex -compatibleArrayDims -I/usr/local/opt/jpeg/include ...
-I/usr/local/opt/gdcm/include/gdcm-3.0/gdcmjpeg ...
jpeg_write.c ...
-L/usr/local/opt/jpeg/lib -L/usr/local/opt/gdcm/lib ...
-ljpeg -lgdcmjpeg16
(I don't know if you actually want -lgdcmjpeg8, -lgdcmjpeg12, or -lgdcmjpeg16, or maybe something else. I'm just guessing here. Consult the GDCM documentation.)

Linking and LOADING static .lib with mex

So, I have a MEX gateway script file that calls my C source code. I've used the -L and -I commands to link my 64-bit compiled GSL libraries (.libs) to my mex executable, which is then compiled under the extension of .mexw64.
I want for this executable to be transferred to another windows machine and run fine, without any GSL libraries installed. That is the the only solution, I don't care what he arguments are regarding the benefits of the dynamic linking/code generation upon compile-time are. I want an executable that has every function not only (of course) pre-declared, but also PRE-DEFINED.
I was lead to believe that this is what 'static' linking is vs. dynamic; but I've read some contradictory definitions all around the interwebs. I need a completely 100% standalone, singular file.
Supposedly you can link the actual .obj file in the mex function, which I can generate, but unfortunately I then get unresolved symbol errors.
Someone else mentioned that I can use the -l (lowercase L) to directly link the actual .lib(s) needed, statically, but that is NOT true.
So is there anyone that can lead me in the right direction, either how to have everything not only linked but to also have the DEFINITIONS linked and ready to load when executable is run--completely standalone, or why I am running into unresolved symbols/linker errors when I include my .obj file? Am I misunderstanding something elementary about the linking process?
Also: To elaborate a bit more, I have the GSL libraries built and linked via Visual Studio for the 64 bit architecture, and I can link it easily with MATLAB, so that is not my problem (any more).
EDIT: I've seen the post here:
Generating standalone MEX file with GNU compilers, including libraries
This doesn't solve my problem, however, although it is the same question. I don't have access to gcc; it's finally compiling on the MSVS12 compiler in MATLAB, I'm not going try to recompile using GCC via MinGW (already tried, couldn't figure it out), so -static and .a options are out.
In your previous post, you mentioned that you decided to compile GSL library with Visual C++, using the VS solution provided by Brian Gladman.
Here is a step-by-step illustration on how to build a MEX-function that links against GSL libraries statically:
Download GNU GSL sources (GSL v1.16)
Download the matching Visual Studio project files (VS2012 for GSL v1.16)
Extract the GSL tarball, say to C:\gsl-1.16
Extract the VS project files on top of the sources, this will overwrite three files as well as add a folder C:\gsl-1.16\build.vc11.
Open Visual Studio 2012, and load the solution: C:\gsl-1.16\build.vc11\gsl.lib.sln
Change the configuration to the desired output: for me I chose platform=x64 and mode=Release
First you must build the gslhdrs project first
Now build the whole solution. This will create two static libraries cblas.lib and gsl.lib stored in C:\gsl-1.16\lib\x64\Release (along with corresponding PDB debugging symbols). It will also create a directory containing the final header files: C:\gsl-1.16\gsl
Next we proceed to build a MEX-function. Take the following simple program (computes some value from a Bessel function, and return it as output):
gsl_test.c
#include "mex.h"
#include <gsl/gsl_sf_bessel.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs != 0 || nlhs > 1) mexErrMsgTxt("Wrong number of args.");
plhs[0] = mxCreateDoubleScalar(gsl_sf_bessel_J0(5.0));
}
This is how to compile the above C code in MATLAB:
>> mex -largeArrayDims gsl_test.c -I"C:\gsl-1.16" -L"C:\gsl-1.16\lib\x64\Release" cblas.lib gsl.lib
Finally we test the MEX-file, and compare it against the value reported by MATLAB's own Bessel function:
>> x = gsl_test()
ans =
-0.1776
>> y = besselj(0,5)
y =
-0.1776
>> max(x-y) % this should be less than eps
ans =
8.3267e-17
Note that the built MEX-function has no external DLL dependencies (other than "Visual C Runtime" which is expected, and the usual MATLAB libraries). You can verify that by using Dependency Walker if you want. So you can simply deploy the gsl_test.mexw64 file alone (assuming the users already have the corresponding VC++ runtime installed on their machines).

How do I get information about compiler (version) that is used by Cython and f2py in IPython?

does anyone know if there is a way to print the compiler (and its version) that is used when I use the Fortran magic and Cython magic in IPython
For example, like the compiler that was used to build Python: platform.python_compiler()
There are probably better ways to do this, but here are two quick ones.
For Cython, the first thing that came to mind was to make a Cython file that passes the Cython compiler and causes an error at the C level.
Here's a simple one.
cdef extern from "nosuchheader.h":
void myfakefunction(int a, double b)
On my computer IPython shows an error from distutils saying that "gcc failed with exit status 1".
I don't currently use the %%fortran magic, but you should be able to see what f2py is doing based on its output.
f2py usually shows which compiler it is using, both when it searches for a compiler, and when it actually calls the Fortran compiler.
To figure that out, I'd recommend compiling some snippet of Fortran code via f2py and looking at the output.
On my windows machine it shows the output as f2py searches for a Fortran compiler, and prints the lines
'Found executable C:\\mingw64\\bin\\gfortran.exe',
'Found executable C:\\mingw64\\bin\\gfortran.exe',
This tells me it is using gfortran.
Further down in the output it also shows the commands used to build the Fortran source code.
The documentation for the fortran magic mentions how to get verbose output.
If you pass the flag -vvv to the fortran magic, it will print the output from f2py.
You could also try looking at the %fortran_config magic mentioned in the documentation.

OpenCV Eclipse configuration in linux

I want to configure eclipse-cdt for opencv in ubuntu. I followed the tutorial Using OpenCV with Eclipse (plugin CDT). However, I was ended up with error message
fatal error: cv.h: No such file or directory DisplayImage.cpp /opencvtest line 1 C/C++ Problem
I checked my configurations as indicated in the tutorial. Everything was fine except the information in 8.b.
As tutorial says for pkg-config --libs opencv, the output should be,
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
But in my case the output was,
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_softcascade.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
Can anyone help me to fix this problem.
Thank you in advance.
Try to change your header from:
#include <cv.h>
#include <highgui.h>
to:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
Thank you for all the answers. But the gain for the problem is bit strange. Here is it.
I am using ubuntu 12.1. I installed opencv using "git" as in the doc. Installation was completed without errors, but i received the above mentioned error.
Since any of the answers (#Alexander and # Ann) didn't make any effect, I re-installed opencv using the downloaded file from "sourceforge". Then it worked perfectly. I think the problem was with the file I downloaded through git.
Anybody has any reason for this issue ?