CBLAS_LAYOUT not declared in gcc version of mkl.h - c++

I'm trying to compile a large code with gcc(version 5.3) compiler, that was compiled with icpc before.
I have troubles with mkl header files that are not the same in gcc as in intel version.
This is the error I'm getting.
error: 'CBLAS_LAYOUT' was not declared in this scope
I looked in the include directory of mkl library and its not in any header. This is the piece of code that's throwing the error.
#include "simgms_math.h"
#include "mkl_lapacke.h"
#include "mkl.h"
#include <iostream>
.
.
CBLAS_LAYOUT layout = (rowMajor == 1) ? CblasRowMajor : CblasColMajor;

typedef CBLAS_ORDER CBLAS_LAYOUT; /* this for backward compatibility */
Adding the line above fixed the issue, after googling about the issue for a while.

Related

How to import matrix market files with eigen library in c++

I'm new to C++ and used to MATLAB. Unfortunatly my matrix size got too big for MATLAB, so I want to try it in C++.
I've found the eigen library 3.3.7 to do matrix manipulations. For this I need to import my matrix market files into Visual Studio 2019. I know some basics in C++ and tried to import my files with loadMarket. After trying to compile it I get like 30 errors in the MarketIO.h file.
This is the file I'm using.
https://eigen.tuxfamily.org/dox/unsupported/MarketIO_8h_source.html
#include <Eigen/Sparse>
#include <unsupported/Eigen/src/SparseExtra/MarketIO.h>
int main(){
typedef Eigen::SparseMatrix<float, Eigen::RowMajor>SMatrixXf;
SMatrixXf A;
Eigen::loadMarket(A, "B.mtx");
}
You must never directly include files from unsupported/Eigen/src/... (or from Eigen/src/...). Just include the corresponding parent header instead:
#include <unsupported/Eigen/SparseExtra>
I probably met the same problem or a closely related one (unfortunately the question has not a detailed error message) while using the SparseExtra module as in the question.
By compiling the code provided in the question I get many errors among which:
/usr/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h:115:20:
error: variable ‘std::ifstream in’ has initializer but incomplete type
115 | std::ifstream in(filename.c_str(),std::ios::in);
| ^~~~~~~~
.... many warnings and errors releated to std::ifstream and std::ofstream ...
/usr/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h:272:9:
error: no match for ‘operator<<’ (operand types are ‘std::ofstream’ {aka
‘std::basic_ofstream<char>’} and ‘const char [42]’)
compiled using g++ -std=c++17, g++ version 12.1.0, Eigen3 v 3.3
I don't know if this is an Eigen bug, but as the first line in the error above shows it seems that the compiler is not able to figure out the definition of std::ifstream.
The problem is solved by modifying the MarketIO.h source code (on my machine located at usr/include/eigen3/unsupported/Eigen/src/SparseExtra/MarketIO.h) as follow:
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud#inria.fr>
// Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsa_wakam#inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef EIGEN_SPARSE_MARKET_IO_H
#define EIGEN_SPARSE_MARKET_IO_H
#include <iostream>
#include <vector>
#include <fstream> // IMPORT THIS HEADER FILE!
... // no changes in the rest of the file
This removes any error and makes the code to compile and properly load the matrix.
Since OP mentions large matrices, another option is fast_matrix_market's Eigen bindings. The Eigen's MarketIO.h loader is sequential, fast_matrix_market is parallel.
#include <fstream>
#include <Eigen/Sparse>
#include <fast_matrix_market/app/Eigen.hpp>
int main(){
typedef Eigen::SparseMatrix<float, Eigen::RowMajor>SMatrixXf;
SMatrixXf A;
std::ifstream file("B.mtx");
fast_matrix_market::read_matrix_market_eigen(file, A);
}

cross compiler raspberry pi incomplete type while native compiler works

I've set up a cross compiler for my raspberry pi, the one I found here: Installing Raspberry Pi Cross-Compiler
Now this has been working fine, up to the point where I want to use an I2c library (i2c-dev.h).
When compiling the code below with the arm-linux-gnueabihf-g++ compiler, I get an error:
In file included from src/I2c.cpp:8:0:
src/../Include/I2c.h:29:18: error: field ‘message’ has incomplete type
struct i2c_msg message;
^
Meanwhile, when I compile the code on a raspi, it simply runs.
#ifndef I2C_H_
#define I2C_H_
#include <linux/i2c-dev.h> // Defines i2c_msg
#include ...
using namespace std;
typedef struct {
struct i2c_msg message;
void (*callback)(int);
int messageID;
} t_msgQueue;
Any ideas on a possible cause, or a solution on how I can make the cross compiler work properly?
My first suspect would be differing GCC versions between the RPi and your cross compiler; GCC has been known to change how it processes #include statements over time.
Barring a version difference, check to ensure that a host include file hasn't been picked up somwhere by accident.
Problem was solved by adding a
#include <linux/i2c.h>
before the i2c-dev headers. Still no idea why the two compilers gave different results...

OpenCV3.10 core.hpp must be compiled in C++

i have installed OpenCV 3.10 and the linked the opencv_world310.lib to release and opencv_world310d.lib to debug.
Moreover I put the compiler options in search directory to ...opencv\build\include. I got a undefined reference error when i left out #include <opencv2/highgui.hpp. Now that i have included it my code looks like this:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <opencv2/highgui.hpp>
int main(void){
printf("HALLO!");
return 0;
}
When i try to build it core.hpp opens and the error: core.hpp must be compiled in C++ occurs.
I am using the GNU GCC Compiler in Codeblocks.
What should i do to solve the problem?
Check you compiler options. Open CV 3.10 C++ API requires code to be compiled as C++, but not C. You can use answer to "CodeBlocks: change project language c and c++" question to change the options.
Also use the new Open CV 3.10 API
#include <opencv2/opencv.hpp>`
instead of all the other Open CV header files. This header includes core functionality. To enable highgui module you need to define HAVE_OPENCV_HIGHGUI in your project settings.

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.

XCode upgraded to 4.4.1 and now I get errors compiling in stl <vector>

Upgraded to XCode 4.4.1 and restarted my machine, recompiled and now get the error below when I try to compile - any suggestions? (It used to compile fine)
(Running on Lion 10.7.4, XCode Version 4.4.1)
#ifndef MYFILE_H
#define MYFILE_H
#include <vector> <-- this line
#include <typeinfo>
#include <string>
#include "assert.h"
using namespace std;
Error message
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/vector:69:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/bits/stl_vector.h:69:1: error: expected member name or ';' after declaration specifiers
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
If this problem is still actual, I suggest you should check the following project setup lines:
C++ Language Dialect (mine: Compiler Default)
C++ Standard Library (mine: Compiler Default)
Compiler for C/C++/Objective-C (mine: Apple LLVM compiler 4.1)
Not all combinations work and not always the "Compiler Default" is the default. I had some problems, too.
(From the error message it looks for me like you are using libstdc++ instead of libc++ but not the gcc compiler or so. I had similar problem after the update.)