Problem compiling and linking voxelyze library - c++

I'm rather new in c++, and I've just installed Ubuntu in my windows PC a few weeks ago.
I have to work with a static library called Voxelyze (I downloaded it from Here. There you can see where are the includes, libs and makefile). And I'm trying to compile an example code (I named it testeo.cpp).
My testeo.cpp path is: c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples
And the voxelyze library path is: c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples/Voxelyze-master
This is the code:
#include "Voxelyze.h"
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
cout << "Testing voxelyze library\n";
CVoxelyze Vx(0.005); //5mm voxels
CVX_Material* pMaterial = Vx.addMaterial(1000000, 1000); //A material with stiffness E=1MPa and density 1000Kg/m^3
CVX_Voxel* Voxel1 = Vx.setVoxel(pMaterial, 0, 0, 0); //Voxel at index x=0, y=0, z=0
CVX_Voxel* Voxel2 = Vx.setVoxel(pMaterial, 1, 0, 0);
CVX_Voxel* Voxel3 = Vx.setVoxel(pMaterial, 2, 0, 0); //Beam extends in the +X direction
Voxel1->external()->setFixedAll(); //Fixes all 6 degrees of freedom with an external condition on Voxel 1
Voxel3->external()->setForce(0, 0, -1); //pulls Voxel 3 downward with 1 Newton of force.
for (int i=0; i<100; i++){
Vx.doTimeStep(); //simulate 100 timesteps.
cout << "Current position: " << (float)Voxel3->position().z << "\n";
}
return 0;
}
This code simply puts three voxels in a row, excerts a downward force in the third one, and then simulates its behavior, and for each timestep simulation it shows its displacement.
Ok, now, in my ubuntu command (after doing sudo apt-get -y update, sudo apt-get -y upgrade and sudo apt-get install build-essential) I firstly go to the voxelyze directory and I do "make clean" and then "make", so that it makes everything that needs to be made:
$ cd /mnt/c/Users/Familia/Desktop/MEMORIA/F/galib247/galib247/examples/Voxelyze-master
$ make clean
$ make
So far so good.
Then, I return to my testeo.cpp path by simply doing cd .. and, using GCC, I try to compile testeo.cpp this way:
$ cd..
$ g++ -Wall -o testeo testeo.cpp -I./Voxelyze-master/include -L./Voxelyze-master/lib/ -lvoxelyze.0.9
But I get the following error message:
testeo.cpp: In function ‘int main()’:
testeo.cpp:15:14: warning: unused variable ‘Voxel2’ [-Wunused-variable]
15 | CVX_Voxel* Voxel2 = Vx.setVoxel(pMaterial, 1, 0, 0);
| ^~~~~~
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::CVX_LinearSolver(CVoxelyze*)':
VX_LinearSolver.cpp:(.text+0x123): undefined reference to `pardisoinit'
/usr/bin/ld: ./Voxelyze-master/lib//libvoxelyze.0.9.a(VX_LinearSolver.o): in function `CVX_LinearSolver::solve()':
VX_LinearSolver.cpp:(.text+0x2a13): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2b17): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2c26): undefined reference to `pardiso'
/usr/bin/ld: VX_LinearSolver.cpp:(.text+0x2e30): undefined reference to `pardiso'
collect2: error: ld returned 1 exit status
Well I don't care much about the warning message, but about the "undefined reference to error".
I think it's an internal library error, (or maybe I'm doing something wrong in my linkage, IDK) because it's complaining about some "LinearSolver" class functions and a "pardiso" thing... but I'm not using them in my testeo.cpp code (at least not directly).
Well, I don't know how to make this thing work, and my engineering degree is on the line here hahaha.
I hope you can help me here, I'd thank you a lot. I'm rather new in this C++-Linux world, but whatever additional information you need in order to solve this mystery, I'll try to do my best to help.
Thanks.

Related

LLDB thinks function call is ambiguous, but it's not

I'm trying to debug a C++ program. I'm on macOS, using CLion IDE, clang compiler, LLDB. I stop the program at a breakpoint (marked with >>):
UnicodeString unicodeFromFile(const std::string &file) {
std::ifstream input(file, std::ios::binary);
cout << "open? " << input.is_open() << endl;
>> std::vector<char> bytes(...);
I want to run po input.is_open(). LLDB reports:
(lldb) po input.is_open()
error: expression failed to parse:
error: <user expression 0>:1:7: call to member function 'is_open' is ambiguous
input.is_open()
~~~~~~^~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/fstream:1169:10: candidate function
bool is_open() const;
^
But it's obviously not ambiguous, since the previous line of code calls it without problem. And it's error message is only listing one function.
Previous to this, I had a different problem where it couldn't find the symbol at all. But I used the advice here, which got me to this point. That answer says to add this to to ~/.lldbinit:
settings set target.import-std-module true
My previous errors looked like:
(lldb) po input.is_open()
error: expression failed to parse:
error: Couldn't lookup symbols:
__ZNKSt3__114basic_ifstreamIcNS_11char_traitsIcEEE7is_openEv
When I try this trivial case with the most recent Xcode (or with TOT lldb) calling the is_open works:
> cat tryifstream.cpp
#include <fstream>
int
main() {
std::ifstream my_str("/tmp/tryifstream.cpp");
bool is_it = my_str.is_open();
return is_it ? 0 : 20;
}
> clang++ -g -O0 /tmp/tryifstream.cpp -o /tmp/a.out
> lldb /tmp/a.out
(lldb) b s -p return
Breakpoint 1: where = a.out`main + 88 at tryifstream.cpp:7:10, address = 0x000000010000379c
(lldb) run
Process 38065 launched: '/tmp/a.out' (arm64)
Process 38065 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x000000010000379c a.out`main at tryifstream.cpp:7
4 main() {
5 std::ifstream my_str("/tmp/tryifstream.cpp");
6 bool is_it = my_str.is_open();
-> 7 return is_it ? 0 : 20;
^
8 }
Target 0: (a.out) stopped.
(lldb) v is_it
(bool) is_it = true
(lldb) expr my_str.is_open()
(bool) $0 = true
If this simple case fails for you, you might try upgrading your Xcode. Getting the lldb expression parser to handle all of std templates is an area of ongoing work and newer lldb's are generally better at it.
If that simple case works for you, but your "real" case still doesn't, and you can make your project or some reduced reproducer available to us, please file a bug with the llvm.org bug reporter, including a copy of your reproducer. It will be hard to figure out what's going wrong in this case w/o being able to trace through the lookups.

Problem with running mlpack sample program

I have installed mlpack via msys2.
Also I have installed gcc via msys2.
Made a simple program in c++ from the code on mlpack website
// This is an interactive demo, so feel free to change the code and click the 'Run' button.
// This simple program uses the mlpack::neighbor::NeighborSearch object
// to find the nearest neighbor of each point in a dataset using the L1 metric,
// and then print the index of the neighbor and the distance of it to stdout.
#include <C:\msys64\mingw64\include\mlpack\core.hpp>
#include <C:\msys64\mingw64\include\mlpack\methods\neighbor_search\neighbor_search.hpp>
using namespace mlpack;
using namespace mlpack::neighbor; // NeighborSearch and NearestNeighborSort
using namespace mlpack::metric; // ManhattanDistance
int main()
{
// Load the data from data.csv (hard-coded). Use CLI for simple command-line
// parameter handling.
arma::mat data("0.339406815,0.843176636,0.472701471; \
0.212587646,0.351174901,0.81056695; \
0.160147626,0.255047893,0.04072469; \
0.564535197,0.943435462,0.597070812");
data = data.t();
// Use templates to specify that we want a NeighborSearch object which uses
// the Manhattan distance.
NeighborSearch<NearestNeighborSort, ManhattanDistance> nn(data);
// Create the object we will store the nearest neighbors in.
arma::Mat<size_t> neighbors;
arma::mat distances; // We need to store the distance too.
// Compute the neighbors.
nn.Search(1, neighbors, distances);
// Write each neighbor and distance using Log.
for (size_t i = 0; i < neighbors.n_elem; ++i)
{
std::cout << "Nearest neighbor of point " << i << " is point "
<< neighbors[i] << " and the distance is " << distances[i] << "." << std::endl;
}
return 0;
}
Trying to run this program as follows,
g++ nearest-neighbour.cpp -o nearest-neighbour -std=c++11 -larmadillo -l mlpack -lomp
I get the following error while executing the executable.
After installing dependency walker I see the above procedure as flagged in red colour, I dont know what it means.
This time I have used below command to compile,
g++ -std=c++11 nearest_neighbour.cpp -o nearest_neighbour.exe -larmadillo -llapack -fopenmp -lmlpack -lboost_serialization-mt -lopenblas

Following c++ code works in leetcode but not in my vscode, why? [duplicate]

This question already has an answer here:
G++ Compiler warning when using c++ 17 updates
(1 answer)
Closed 1 year ago.
I am currently working on a leetcode question, and try to track down the code process in my end, this is my solution:
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
vector<int> direction{-1, 0, 1, 0, -1};
int maxAreaOfIsland(vector<vector<int>>&grid){
int m = grid.size(), n = m ? grid[0].size() : 0, local_area, area = 0, x, y;
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
if(grid[i][j]){
local_area = 1;
grid[i][j] = 0;
stack<pair<int, int>> island;
island.push({i, j});
while(!island.empty()){
auto [r, c] = island.top(); \\problem line, vscode can't understand it
island.pop();
for (int k = 0; k < 4; ++k){
x = r + direction[k], y = c + direction[k + 1];
if(x>=0 && x<m && y>=0 && y<n && grid[x][y]==1){
grid[x][y] = 0;
++local_area;
island.push({x, y});
}
}
}
area = max(area, local_area);
}
}
}
return area;
}
this code works on the leetcode side, but not mine, here is the warning
[Running] cd "c:\Users\chen1\OneDrive\Desktop\C_C++tut\" && g++ leetcode695.cpp -o leetcode695 && "c:\Users\chen1\OneDrive\Desktop\C_C++tut\"leetcode695
leetcode695.cpp: In function 'int maxAreaOfIsland(std::vector<std::vector<int> >&)':
leetcode695.cpp:23:16: warning: structured bindings only available with -std=c++17 or -std=gnu++17
auto [r, c] = island.top();
^
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
[Done] exited with code=1 in 0.932 seconds
Can someone explains why, although I get an alternative way to replace it, it is still annoying and perplexing
thanks for helping
additionally!!!
I actually have my main function; the problem here is a syntax error where leetcode's compiler recognizes it, but not g++, the line that causes the problem is auto [r, c] = island.top();, if I alter it to
int r = get<0>(island.top());
int c = get<1>(island.top());
then it works fine, I just don't understand why leetcode compiler can understand it, but not g++
The linker error (not the warning) is what is causing the build to fail (scroll sideways!):
[...]crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
occurs in MinGW gcc when your code lacks either a main() or WinMain() entry point. As yours does. I guess leetcode (which I have never heard of or used) provides a test harness for you to run the function? It compiles - the message is a linker error, so it cannot form an executable - you need a main().
With respect to the warning, again you need to scroll to the end of the message:
leetcode695.cpp:23:16: warning: structured bindings only available
with -std=c++17 or -std=gnu++17
auto [r, c] = island.top();
can be resolved by specifying C++17 (or higher) compilation (or not using structured bindings). A Windows/VSCode specific solution is discussed at G++ Compiler warning when using c++ 17 updates, but fundamentally it is about setting the compiler switch -std=c++17.

Undefined symbols for architecture x86_64: missing package?

I am doing different exercises in c++ for preparing my exam at university.
I am pretty sure they are all without heavy mistake and should complement.
All codes can't complement with the same error log:
Undefined symbols for architecture x86_64:
[hundreds lines of error log]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The error log between is about every single line of code.
I am wondering if I've missed to install some package for complement c++ on my device.
Code Example:
#include <iostream>
#include <new>
int main () {
int n;
std::cout<<"How many value do you want to enter to your list?"<< std::endl;
std::cin>>n;
int* numbArray = new int[n];
for(int i = 0; i<n; i++) {
std::cout<<"Enter the"<< i+1 <<". value!"<<std::endl;
std::cin>>numbArray[i];
}
std::cout << "List of value: " << std::endl;
for(int i=0; i<n; i++ ) {
std::cout<<numbArray[i]<<" "<<std::endl;
}
std::cout<<"end of arrays"<<std::endl;
delete[]numbArray;
return 0;
}
My operating System is macOS Catalina 10.15.2
Thanks for your help.
There are no explicit/implicit linker symbols. This is a symbol in the C++ standard library. How to you call the compiler and linker? Do you happen to link with "gcc" instead of "g++", as it should be?
Just as Erlkoeing said, using "g++" instead of "gcc" for calling the compiler and linker works fine.

Undefined reference to timeGetTime() in g++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I'm using g++ command line under Windows 10 to build a basic timing loop and am getting the error: " undefined reference to `timeGetTime#0' " when attempting to compile.
The code, itself, is pretty simple:
#include <windows.h>
#include <iostream>
using namespace std;
int main(){
int start = timeGetTime();
int finish = 10000;
int benchmarks [9] = {1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000};
int i = 0;
int time = timeGetTime() - start;
while( time < finish){
if(time > benchmarks[i]){
cout << benchmarks[i] / 1000 << endl;
i++;
}
return 0;
}
Not sure what I need to do to get g++ to play nicely with the WinAPI. I can't help but wonder if it's an issue with the linker.
You have to link libwinmm.
Undefined reference is an error which occures when your compiler knows that the function exist, it knows its prototype, but can't find its corpse. When it is not one of your functions, it surely means you miss to link a library.