I want to link armadillo-11.4.0 to Code::blocks C++ project in Windows 11. I already gave the path to include folder and library folder using Project Build options>>Search directories. Also, in Build options>>linker settings I added the "libopenblas.lib" which is the precompiled openblas library I found in the armadillo\examples\lib_win64 folder. However, When I compile the example code given below, I get the following error.
ld.exe||cannot find -lopenblas.lib|
#include <iostream>
#include <armadillo>
using namespace arma;
int
main()
{
std::cout << "*** smoke test start" << std::endl;
uword N = 5;
mat A = reshape(regspace(1, N*N), N, N);
A.diag() += randu<vec>(N);
mat B;
bool status = expmat(B,A);
A.print("A:");
B.print("B:");
std::cout << ((status) ? "*** smoke test okay" : "*** smoke test failed") << std::endl;
return (status) ? 0 : -1;
}
Can someone explain me how to compile this successfully?
Related
Hi I get a linking error when compiling my program with the gcc compiler on cygwin. The first picture is a simple sample program from the boost filesystem libraries tutorial page where I have included filesystem.hpp in the boost folder. Beneath that is the picture of my linker error when I try to compile with the following command:
g++ -I C:/Users/Ejer/Desktop/c++Dep/boost_1_77_0 -I C:/Users/Ejer/Desktop/c++Dep/eigen-3.4.0 -L C:/Users/Ejer/Desktop/c++Dep/boost_1_77_0/stage/lib test.cpp -o ser
Here I try to compile my program test.cpp with the eigen and boost libraries and set the includer path that they tell me to set as the path after I have built the library with b2.exe. I have also linked to the lib files for boost. I have also tried linking to the different filesystem lib files specifically. Thanks in advance
#include <iostream>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut3 path\n";
return 1;
}
path p (argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (directory_entry& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
}
I get a linking error when compiling my program
No, you don't. You are getting a linking error when linking your program, not when compiling it.
The reason: you didn't supply the library (-L C:/Users/.... tells the linker where to search for libraries; not which libraries to link). Your command line should look something like:
g++ -I ... -L ... test1.cpp -o ser -lboost_filesystem
I downloaded a webcam_face_pose_ex.cpp file from GitHub and now i want to compile and run it on my mac.
#include <dlib/opencv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <X11/Xlib.h>
using namespace dlib;
using namespace std;
int main()
{
try
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
image_window win;
// Load face detection and pose estimation models.
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
// Grab and process frames until the main window is closed by the user.
while(!win.is_closed())
{
// Grab a frame
cv::Mat temp;
if (!cap.read(temp))
{
break;
}
// Turn OpenCV's Mat into something dlib can deal with. Note that this just
// wraps the Mat object, it doesn't copy anything. So cimg is only valid as
// long as temp is valid. Also don't do anything to temp that would cause it
// to reallocate the memory which stores the image as that will make cimg
// contain dangling pointers. This basically means you shouldn't modify temp
// while using cimg.
cv_image<bgr_pixel> cimg(temp);
// Detect faces
std::vector<rectangle> faces = detector(cimg);
// Find the pose of each face.
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
shapes.push_back(pose_model(cimg, faces[i]));
// Display it all on the screen
win.clear_overlay();
win.set_image(cimg);
win.add_overlay(render_face_detections(shapes));
}
}
catch(serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
I tried g++ webcam_face_pose_ex.cpp command but I get:
webcam_face_pose_ex.cpp:30:10: fatal error: 'dlib/opencv.h' file not found
#include <dlib/opencv.h>
^~~~~~~~~~~~~~~
1 error generated.
Was Wondering what I could do to fix this?
The Example File Is Not Meant to be Compiled Using g++
Read the following to learn a bit about the -I flag and #include statements:
The webcam_face_pose_ex.cpp is part of a larger project and you won't be able to compile it on its own because it depends on other files. The #include directive specifies that in order to compile this program, code from the file specified by #includemust be compiled first. This means the entire dlib must be downloaded before compiling webcam_face_pose_ex.cpp. This project also requires opencv2 so we can download it and place the opencv2 folder in the dlib project folder.
Now we can open terminal and change directory into the dlib project folder and compile the file using the following command:
g++ -I. examples/webcam_face_pose_ex.cpp
Note we're specifying the directory of where to find the files specified by #include using the -I parameter as -I. this means to search the current working directory for the files. There it will find the dlib folder and dlib/opencv.h.
How ever, this isn't enough. When you execute the command, you'll encounter an error opencv2/opencv_modules.hpp: No such file or directory.
Solution
The dlib project documentation states that the examples should be built using cmake. Make sure to use cmake to compile the examples.
I am new to C++, and now learning it using code blocks (version: codeblocks-16.01mingw-setup.exe). My test codes are as follows:
#include<iostream>
#include<stdlib.h>
int main()
{
int sum = 0, val = 1;
// keep executing the until val is greater than 10
while (val <=10 ) {
sum += val; // short-cut assignment
++val; // add 1 to val
}
std::cout << "Sum of 1 to 10 inclusive is "
<< sum << std::endl;
system("pause");
return 0;
}
These codes are written in an empty file named ex1.cpp. Then I tested by click "Build and run". As a result, another file main.cpp (I did not write this) pops up:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Screenshot attached for your better checking:
The reason why you are getting this error is because your compiler settings is not correct.You need to make sure that you use GNU GCC MinGW Compailer.Go To Settings-->Compiler and make sure every thing is same as on the screen shot.
Solving common codeblocks problems :Link
I really did something wrong about coding:
when I create an empty file in the project, it will result in two main functions in the that project one of which is that "hello world" file automatically generated, which is not allowed by C++.
To build it successfully, what I did is to overwrite the codes in the main.cpp.
Hello guys I am developing a simple openCV application with eclipse CDT;
Here is my code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat M(2,2, CV_8UC3, Scalar(0,0,255));
cout << "M = " << endl << " " << M << endl << endl;
return 0;
}
I have built the project and when I try to run, I am getting this error
The program file specified in the launch configuration does not exist
D:\AndroidKeyStore\ExOpen\Debug\ExOpen.exe not found
Assuming the compilation didn't fail, the executable you're building appears to be different from the one you're trying to run in your configuration.
I'm not familiar with Eclipse CDT but you should
go to the Debug Configurations window for your project
select your launch configuration
change the exe you pasted above to the one your project is configured to build (you can find it in the project properties->C/C++ Build->Build directory)
I've got a pretty basic console program here, to determine if a folder or file exists or not using stat:
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main() {
char path[] = "myfolder/";
struct stat status;
if(stat(path,&status)==0) { cout << "Folder found." << endl; }
else { cout << "Can't find folder." << endl; } //Doesn't exist
cin.get();
return 0;
}
I have also tried the access version:
#include <iostream>
#include <io.h>
using namespace std;
int main() {
char path[] = "myfolder/";
if(access(path,0)==0) { cout << "Folder found." << endl; }
else { cout << "Can't find folder." << endl; } //Doesn't exist
cin.get();
return 0;
}
Neither of them find my folder (which is right there in the same directory as the program). These worked on my last compiler (the default one with DevCpp). I switched to CodeBlocks and am compiling with Gnu GCC now, if that helps. I'm sure it's a quick fix - can someone help out?
(Obviously I'm a noob at this so if you need any other information I've left out please let me know).
UPDATE
The problem was with the base directory. The updated, working program is as follows:
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main() {
cout << "Current directory: " << system("cd") << endl;
char path[] = "./bin/Release/myfolder";
struct stat status;
if(stat(path,&status)==0) { cout << "Directory found." << endl; }
else { cout << "Can't find directory." << endl; } //Doesn't exist
cin.get();
return 0;
}
ANOTHER UPDATE
Turns out that a trailing backslash on the path is big trouble.
Right before your stat call, insert the code:
system("pwd"); // for UNIXy systems
system("cd"); // for Windowsy systems
(or equivalent) to check your current directory. I think you'll find it's not what you think.
Alternatively, run the executable from the command line where you know what directory you're in. IDEs will frequently run your executable from a directory you may not expect.
Or, use the full path name so that it doesn't matter which directory you're in.
For what it's worth, your first code segment works perfectly (gcc under Ubuntu 10):
pax$ ls my*
ls: cannot access my*: No such file or directory
pax$ ./qq
Cannot find folder.
pax$ mkdir myfolder
pax$ ll -d my*
drwxr-xr-x 2 pax pax 4096 2010-12-14 09:33 myfolder/
pax$ ./qq
Folder found.
Are you sure that the current directory of your running program is what you expect it to be? Try changing path to an absolute pathname to see if that helps.
Check your PWD when you running your program. This problem is not caused by compiler. You DevCpp may set a working directory for your program automatically.
You can find out why stat() failed (which is a C function, not C++, by the way), by checking errno:
#include <cerrno>
...
if (stat(path,&status) != 0)
{
std::cout << "stat() failed:" << std::strerror(errno) << endl;
}