Undefined reference to `ParMETIS_V3_PartMeshKway' - c++

I use this c++ code
#include <iostream>
#include "parmetis.h"
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
int np = 3; int ne = 36;
idx_t *elmdist = new idx_t[np+1]; for (int i=0; i<np+1; i++) {elmdist[i] = (i-1)*ne/np;} elmdist[np] = ne;
idx_t *eptr = new idx_t[ne+1]; for (int i=0; i<ne+1; i++) {eptr[i] = (i-1)*3;}
idx_t eind_[] = {13, 14, 15,
13, 16, 17,
2, 17, 6,
4, 15, 10,
13, 15, 19,
13, 17, 18,
13, 19, 16,
13, 18, 14,
1, 5, 16,
3, 9, 14,
7, 8, 18,
11, 12, 19,
1, 20, 12,
3, 21, 8,
7, 18, 23,
11, 19, 22,
2, 23, 17,
4, 22, 15,
14, 25, 15,
16, 24, 17,
15, 22, 19,
17, 23, 18,
1, 16, 20,
3, 14, 21,
5, 24, 16,
9, 25, 14,
16, 19, 20,
14, 18, 21,
6, 17, 24,
10, 15, 25,
5, 6, 24,
9, 10, 25,
8, 21, 18,
12, 20, 19,
2, 7, 23,
4, 11, 22};
idx_t *eind = eind_;
idx_t *elmwgt = NULL;
idx_t wgtflag_[] = {0};
idx_t *wgtflag = wgtflag_;
idx_t numflag_[] = {0};
idx_t *numflag = numflag_;
idx_t ncon_[] = {1};
idx_t *ncon = ncon_;
idx_t ncommonnodes_[] = {2};
idx_t *ncommonnodes = ncommonnodes_;
idx_t nparts_[] = {np};
idx_t *nparts = nparts_;
real_t *tpwgts = new real_t[np*ncon[0]]; for(int i=0; i<np*ncon[0]; i++) {tpwgts[i] = 1.0/np;}
real_t ubvec_[] = {1.05};
real_t *ubvec = ubvec_;
idx_t options_[] ={0, 0, 0};
idx_t *options =options_;
idx_t *edgecut=NULL;
idx_t *part=NULL;
MPI_Comm *comm=NULL;
ParMETIS_V3_PartMeshKway(elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, ubvec, options, edgecut, part, comm);
MPI_Finalize();
return 0;
}
In allmet I insert all files from metis and parmetis.
Try to compile using OpenMPI with g++ compiler:
mpicxx -I path/allmet/include -L path/allmet/lib par.cpp
I get error:
undefined reference to `ParMETIS_V3_PartMeshKway'
With cmake:
cmake_minimum_required(VERSION 2.8.9)
project (MetisTest)
find_package(MPI)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories("path/allmet/include")
link_directories("path/allmet/lib")
add_executable(metisTest par.cpp)
target_link_libraries(metisTest ${MPI_C_LIBRARIES})
I have:
undefined reference to `ParMETIS_V3_PartMeshKway'
in function `MPI::Intracomm::Intracomm()':
undefined reference to `MPI::Comm::Comm()'
and many others
So what I can do? Metis work perfect but with parmetis I can't do anything.
Ubuntu 18.10, gcc 8.2.0.

You also need to link against Parmetis itself:
target_link_libraries(metisTest ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PARMETIS_LIBS})
Do note that:
link_directories("path/allmet/lib")
Is irrelevant for the link. If you still want to use the command line, you need:
mpicxx -Ipath/allmet/include -Lpath/allmet/lib -lparmetis -lmetis par.cpp

Related

16X32 RGB Led matrix, multiple definition of matrix

I'm trying to make a project using the 16x32 RGB Led matrix, from the Adafruit store, but for some reason Visual Studio keeps telling me I've defined the matrix class multiple times.
This all started happening when I started making my own classes for my program (I'm still learning OOP). I have put define protection in the header file where I instantiate the matrix class, so that shouldn't be the problem
I've tried moving the class definition around. When I put it into the cpp file where I wanted to use it I stopped getting the multiple definition error, but then the matrix doesn't draw anything.
I've tried parsing a pointer to the matrix class to the class where I wanted to use the matrix but then I get this weird error where the matrix redraws the first thing it has to draw over and over again and it stops responding to serial input/doesn't give any serial output.
code:
//===========Matrix.h===========
#ifndef MATRIX_H
#define MATRIX_H
#include "RGBmatrixPanel.h"
#include <SPI.h>
#include <Adafruit_I2CDevice.h>
#define CLK 8
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
#endif
//===========main.cpp===========
#include <Arduino.h>
#include "GuiDrawer.h"
GuiDrawer guiDrawer;
void setup() {
Serial.begin(9600);
guiDrawer.drawBaseGui();
}
void loop() {}
//===========GuiDrawer.h===========
#ifndef GUIDRAWER_H
#define GUIDRAWER_H
#include <Arduino.h>
#include "matrix.h"
class GuiDrawer {
private:
enum COLOURS {
BLACK = 0, //0
WHITE, //1
RED, //2
YELLOW, //3
DARKER_YELLOW, //4
DARKEST_YELLOW, //5
GRAY //6
};
enum SHAPES {
HEART = 0, //0
AMMO, //1
COIN //2
};
const int HEARTSIZE_X = 8;
const int HEARTSIZE_Y = 8;
const int HEARTSHAPE [8][8] = {
{0, 2, 2, 0, 0, 2, 2, 0},
{2, 2, 1, 2, 2, 2, 2, 2},
{2, 1, 2, 2, 2, 2, 2, 2},
{2, 1, 2, 2, 2, 2, 2, 2},
{2, 2, 2, 2, 2, 2, 2, 2},
{0, 2, 2, 2, 2, 2, 2, 0},
{0, 0, 2, 2, 2, 2, 0, 0},
{0, 0, 0, 2, 2, 0, 0, 0},
};
const int COINSIZE_X = 8;
const int COINSIZE_Y = 7;
const int COINSHAPE [8][7] = {
{0, 0, 4, 4, 4, 0, 0},
{0, 4, 3, 3, 3, 4, 0},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{0, 4, 3, 3, 3, 4, 0},
{0, 0, 4, 4, 4, 0, 0}
};
const int AMMOSIZE_X = 8;
const int AMMOSIZE_Y = 6;
const int AMMOSHAPE [8][6] = {
{0, 6, 0, 0, 6, 0},
{6, 6, 6, 6, 6, 6},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5}
};
void drawShape(SHAPES shape, int startX, int startY);
void pixelDrawer(COLOURS colourToDraw, int drawX, int drawY);
public:
GuiDrawer();
void drawBaseGui();
};
#endif
//===========GuiDrawer.cpp===========
#include <Arduino.h>
#include "GuiDrawer.h"
GuiDrawer::GuiDrawer() {
matrix.begin();
Serial.begin(9600);
}
void GuiDrawer::drawBaseGui() {
drawShape(HEART, 0, 0);
drawShape(COIN, 0, 8);
drawShape(COIN, 25, 8);
Serial.println("drawn base gui");
}
void GuiDrawer::drawShape(SHAPES shape, int startX, int startY) {
switch (shape) {
case HEART:
for (int i = 0; i < HEARTSIZE_X; i++) {
for (int j = 0; j < HEARTSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)HEARTSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
Serial.println();
}
break;
case AMMO:
for (int i = 0; i < AMMOSIZE_X; i++) {
for (int j = 0; j < AMMOSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)AMMOSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
}
break;
case COIN:
for (int i = 0; i < COINSIZE_X; i++) {
for (int j = 0; j < COINSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)COINSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
}
break;
default:
break;
}
}
void GuiDrawer::pixelDrawer(COLOURS colourToDraw, int drawX, int drawY) {
switch (colourToDraw) {
case BLACK:
matrix.drawPixel(drawX, drawY, matrix.Color333(0, 0, 0));
Serial.print("black ");
break;
case WHITE:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 255, 255));
Serial.print("white ");
break;
case RED:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 0, 0));
Serial.print("red ");
break;
case YELLOW:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 255, 0));
break;
case DARKER_YELLOW:
matrix.drawPixel(drawX, drawY, matrix.Color888(16, 16, 0));
break;
default:
break;
}
}
error I am getting:
.pio\build\uno\src\main.cpp.o (symbol from plugin): In function `matrix':
(.text+0x0): multiple definition of `matrix'
.pio\build\uno\src\GuiDrawer.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
led matrix: https://www.adafruit.com/product/420

error: assignment of function 'void digitalWrite(uint8_t, uint8_t)

Warning: I'm new to C++ (and most of programming in general) and am learning the language to be able to write code for my arduino
I'm learning how to use a shift register using the Arduino IDE which i believe is in C++.
Here is the code:
const int latchPin = 12; // connected to ST_CP of 74HC595
const int clockPin = 8; // connected to SH_CP of 74HC595
const int dataPin = 11; // connected to DS of 74HC595
// display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, b, C, d, E, F
int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);
void setup()
{
//set pins to output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop()
{
//loop from 0 to 256
for(int num = 0; num < 16; num++)
{
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]); //MSBFIRST means most significant bit first
// return the latch pin high to signal chip that it no longer needs to listen for information
digitalWrite=(latchPin, HIGH); // pull the latchpin to save the data
delay(1000); // wait for a second
}
}
and here is the error which I do not understand what it means and what I should do about it
shift_register:5:92: error: array must be initialized with a brace-enclosed initializer
int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
C:\Users\HP\Desktop\VSc Code\Arduino\shift_register\shift_register.ino: In function 'void loop()':
shift_register:22:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite=(latchPin, HIGH); // pull the latchpin to save the data
^
shift_register:22:33: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
exit status 1
array must be initialized with a brace-enclosed initializer
This line is the problem:
int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);
Change it to:
int datArray[16] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};

How to get a blurred translucent QML Window (similar to Fluent Design guidelines) on Windows 10?

I would like to get a semi-transparent blurred window in QML on Windows 10 similar to the Fluent Design guidelines (example). I know you can make a transparent window:
Window{
visible: true
color: "transparent"
}
but this doesn't achieve the blur effect I am looking at. I am also aware that one can blur elements inside the windows using QtGraphicalEffects like FastBlur but I would like to blur the entire window itself.
Is there a way to achieve this? I have also tried using the QtWinExtras module and call QtWin::enableBlurBehindWindow but this doesn't work either:
QObject *root = engine.rootObjects()[0];
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
if (!window) {
qFatal("Error: Your root item has to be a window.");
return -1;
}
QtWin::enableBlurBehindWindow(window);
Ok so I found a solution that turned out to be easier than I thought it would be. Officially Microsoft does not provide an API to achieve what I was looking for. I stumbled across this thread and I found this. From there I adapted the code to my needs, I created a header file containing:
#ifndef STRUCTS_H
#define STRUCTS_H
#include <windef.h>
#pragma once
typedef enum _WINDOWCOMPOSITIONATTRIB
{
WCA_UNDEFINED = 0,
WCA_NCRENDERING_ENABLED = 1,
WCA_NCRENDERING_POLICY = 2,
WCA_TRANSITIONS_FORCEDISABLED = 3,
WCA_ALLOW_NCPAINT = 4,
WCA_CAPTION_BUTTON_BOUNDS = 5,
WCA_NONCLIENT_RTL_LAYOUT = 6,
WCA_FORCE_ICONIC_REPRESENTATION = 7,
WCA_EXTENDED_FRAME_BOUNDS = 8,
WCA_HAS_ICONIC_BITMAP = 9,
WCA_THEME_ATTRIBUTES = 10,
WCA_NCRENDERING_EXILED = 11,
WCA_NCADORNMENTINFO = 12,
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
WCA_VIDEO_OVERLAY_ACTIVE = 14,
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
WCA_DISALLOW_PEEK = 16,
WCA_CLOAK = 17,
WCA_CLOAKED = 18,
WCA_ACCENT_POLICY = 19,
WCA_FREEZE_REPRESENTATION = 20,
WCA_EVER_UNCLOAKED = 21,
WCA_VISUAL_OWNER = 22,
WCA_HOLOGRAPHIC = 23,
WCA_EXCLUDED_FROM_DDA = 24,
WCA_PASSIVEUPDATEMODE = 25,
WCA_LAST = 26
} WINDOWCOMPOSITIONATTRIB;
typedef struct _WINDOWCOMPOSITIONATTRIBDATA
{
WINDOWCOMPOSITIONATTRIB Attrib;
PVOID pvData;
SIZE_T cbData;
} WINDOWCOMPOSITIONATTRIBDATA;
typedef enum _ACCENT_STATE
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4 1803
ACCENT_ENABLE_HOSTBACKDROP = 5, // RS5 1809
ACCENT_INVALID_STATE = 6
} ACCENT_STATE;
typedef struct _ACCENT_POLICY
{
ACCENT_STATE AccentState;
DWORD AccentFlags;
DWORD GradientColor;
DWORD AnimationId;
} ACCENT_POLICY;
typedef BOOL (WINAPI *pfnGetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
typedef BOOL (WINAPI *pfnSetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
#endif // STRUCTS_H
And then in my main.cpp:
#ifdef Q_OS_WIN
#include <QQuickWindow>
#include <windows.h>
#include <WinUser.h>
#include "structs.h" // my header file
#endif
#ifdef Q_OS_WIN
QObject *root = engine.rootObjects()[0];
QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
if (!window) {
qFatal("Error: Your root item has to be a window.");
return -1;
}
HWND hwnd = (HWND)window->winId();
HMODULE hUser = GetModuleHandle(L"user32.dll");
if (hUser)
{
pfnSetWindowCompositionAttribute setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(hUser, "SetWindowCompositionAttribute");
if (setWindowCompositionAttribute)
{
ACCENT_POLICY accent = { ACCENT_ENABLE_BLURBEHIND, 0, 0, 0 };
WINDOWCOMPOSITIONATTRIBDATA data;
data.Attrib = WCA_ACCENT_POLICY;
data.pvData = &accent;
data.cbData = sizeof(accent);
setWindowCompositionAttribute(hwnd, &data);
}
}
#endif
This enables the "Acrylic Material" effect I was looking for (in QML you have to set the window color to "transparent").

Why does tone function from arduino does not work in RTOS?

I am trying to output a song using the Piezoelectric buzzer on my Arduino. Running the code without RTOS functionalities works well, however, when i place the code into an RTOS task, the buzzer does not work. I am buzzled by this.
Running the code without RTOS Task function works but when implemented with RTOS, it doesn't work. It seems like the tone() function does not execute.
#include <Arduino.h>
#include <avr/io.h>
#include <FreeRTOS.h>
#include <task.h>
//Tones
#define d 294 // 294 Hz
#define e 329 // 329 Hz
#define fSharp 370 // 369.994 Hz
#define g 392 // 392 Hz
// Define a special note, 'R', to represent a rest
#define R 000
#define babySharkOutput 11
int babyShark[] = { //Note of the song, 0 is a rest/pulse
d, e, g, g, g, g, g, g,
d, e, g, g, g, g, g, g,
d, e, g, g, g, g, g, g,
g, g, fSharp, R
};
int babySharkDuration[] = {
400, 200, 50, 50, 75, 50, 50, 75,
400, 200, 50, 50, 75, 50, 50, 75,
400, 200, 50, 50, 75, 50, 50, 75,
75, 75, 250, 1000
};
int babySharkNotePause[] = {
50, 60, 25, 20, 25, 15, 25, 40,
50, 60, 25, 20, 25, 15, 25, 40,
50, 60, 25, 20, 25, 15, 25, 40,
30, 20, 50, 200
};
void songTask(void *p) {
TickType_t xLastWakeTime = 0 ;
const TickType_t xPeriod = pdMS_TO_TICKS(1000);
while(1) {
for (int i = 0; i < 28; i ++){
tone(babySharkOutput, babyShark[i], babySharkDuration[i]);
int songDelay = babySharkNotePause[i] * songSpeed;
vTaskDelay(songDelay);
}
vTaskDelayUntil( &xLastWakeTime, xPeriod);
}
}
void setup() {
pinMode(babySharkOutput, OUTPUT);
}
void loop() {
xTaskCreate(songTask, "songTask", STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
}
Hmm I expected this would run well because it can be run without the RTOS features, but there's something wrong here and I can't figure it out.

X/Y position of path endpoint in Raphael

I need to retrieve the X/Y coordinate of the end of a path drawn in Raphael. I've found a way that works by introspecting the path afterwards in SVG browsers but this approach does not work in VML browsers.
Example:
var paper = Raphael('canvas', 200, 200);
var p = paper.path(['M', 10, 10, 'l', 30, 30, 'a', 20, 30, 0, 1, 0, 40, 10, 'a', 20, 30, 0, 1, 0, 40, 10, 'l', -15, -18]);
var lastP = p.attrs.path[p.attrs.path.length - 1];
paper.circle(lastP[lastP.length - 2], lastP[lastP.length - 1], 3);
http://jsfiddle.net/sY4Up/1/
In Chrome, a circle gets drawn at the endpoint through path introspection. In IE 6/7/8, the circle does not draw because the path definition does not get decomposed/normalized.
use getPointAtLength and getTotalLength to find the position.
window.onload = function() {
var paper = Raphael('canvas', 200, 200);
var p = paper.path(['M', 10, 10, 'l', 30, 30, 'a', 20, 30, 0, 1, 0, 40, 10, 'a', 20, 30, 0, 1, 0, 40, 10, 'l', -15, -18]);
var lastP = p.attrs.path[p.attrs.path.length - 1];
paper.circle(lastP[lastP.length - 2], lastP[lastP.length - 1], 3);
var pt = p.getPointAtLength(p.getTotalLength());
paper.circle(pt.x,pt.y,10);
};