News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Undefined reference

Started by Kaz, May 06, 2021, 03:01:32 PM

Previous topic - Next topic

Kaz

Hello, I'm tryin to compile a program. And although command line works perfectly, I can't seem to do the same thing from Code::Blocks. Could you tell me how I can solve this? Thanks in advance.

This one below is the command in in command line

$ g++ -std=c++11 -I /usr/local/MATLAB/R2021a/extern/include/ -L /usr/local/MATLAB/R2021a/extern/bin/glnxa64/ -pthread main.cpp -lMatlabDataArray -lMatlabEngine

And the attached image is (a part of) the build log in Code::Blocks.

BlueHazzard

You have to split linker and compiler options

your compiler options:

-std=c++11
-I /usr/local/MATLAB/R2021a/extern/include/


the linker options:

-L /usr/local/MATLAB/R2021a/extern/bin/glnxa64/
-lMatlabDataArray
-lMatlabEngine


In Project->Build options->Select your project name on the left->Compiler settings->Compiler flags-> Tick the c++11 flag
In Project->Build options->Select your project name on the left->Search directories->Compiler->Add-> "/usr/local/MATLAB/R2021a/extern/include/"
In Project->Build options->Select your project name on the left->Search directories->Linker->Add-> "/usr/local/MATLAB/R2021a/extern/bin/glnxa64/"
In Project->Build options->Select your project name on the left->Linker settings->Link libraries->Add-> "MatlabDataArray"
In Project->Build options->Select your project name on the left->Linker settings->Link libraries->Add-> "MatlabEngine"
In Project->Build options->Select your project name on the left->Linker settings->Other options-> "-pthread"

Kaz

Thank you very much. Now it perfectly works!


Quote from: BlueHazzard on May 06, 2021, 03:48:09 PM
You have to split linker and compiler options

your compiler options:

-std=c++11
-I /usr/local/MATLAB/R2021a/extern/include/


the linker options:

-L /usr/local/MATLAB/R2021a/extern/bin/glnxa64/
-lMatlabDataArray
-lMatlabEngine


In Project->Build options->Select your project name on the left->Compiler settings->Compiler flags-> Tick the c++11 flag
In Project->Build options->Select your project name on the left->Search directories->Compiler->Add-> "/usr/local/MATLAB/R2021a/extern/include/"
In Project->Build options->Select your project name on the left->Search directories->Linker->Add-> "/usr/local/MATLAB/R2021a/extern/bin/glnxa64/"
In Project->Build options->Select your project name on the left->Linker settings->Link libraries->Add-> "MatlabDataArray"
In Project->Build options->Select your project name on the left->Linker settings->Link libraries->Add-> "MatlabEngine"
In Project->Build options->Select your project name on the left->Linker settings->Other options-> "-pthread"