Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Kaz on May 06, 2021, 03:01:32 pm

Title: Undefined reference
Post by: Kaz on May 06, 2021, 03:01:32 pm
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.
Title: Re: Undefined reference
Post by: BlueHazzard on May 06, 2021, 03:48:09 pm
You have to split linker and compiler options

your compiler options:
Code
-std=c++11
-I /usr/local/MATLAB/R2021a/extern/include/

the linker options:
Code
-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"
Title: Re: Undefined reference
Post by: Kaz on May 06, 2021, 03:59:43 pm
Thank you very much. Now it perfectly works!


You have to split linker and compiler options

your compiler options:
Code
-std=c++11
-I /usr/local/MATLAB/R2021a/extern/include/

the linker options:
Code
-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"