I'm trying to create a chat programm for the TI-Nspire Calc via the serial port. So I installed the ndless SDK and nspireio lib to make the communication and it kind of works because there is an infite repetition of the message so I wrote this:
if(uart_ready()) {
char input[100] = {0};
uart_getsn(input,100);
if(oldinput != input) {
nio_puts(input);
oldinput = input;
}
}
But when I compile it give me this error:
root#Kali-Linux:~/TINSPIRE/Ndless/ndless-sdk/samples/uart# make
nspire-g++ -Wall -W -marm -Os -c hello.cpp
hello.cpp: Dans la fonction « int main() »:
hello.cpp:61:14: error: affectation de tableau invalide
oldinput = input;
^~~~~
Makefile:33 : la recette pour la cible « hello.o » a échouée
make: *** [hello.o] Erreur 1
What I'm doing wrong?
If oldinput is also a char array,
replace oldinput=input with
strcpy(oldinput,input);
You should declare oldinput:
char oldinput[100] = {0};
memcpy(oldinput, input, sizeof(char) * 100);
Related
This question already has answers here:
How to add "-l" (ell) compiler flag in CMake
(2 answers)
Closed 3 years ago.
I create a cmakelist.txt for a project graphique. I use the library irrlicht. I have a probleme after i had "cmake .", i do make i have error
cmakelist.txt
cmake_minimum_required(VERSION 3.11)
PROJECT(toto)
INCLUDE_DIRECTORIES(
"/usr/include/irrlicht"
${PROJECT_SOURCE_DIR}/include
)
SET(GCC_COVERAGE_COMPILE_FLAGS "-lIrrlicht -lGL -lGLU -lXxf86vm-lX11")
#SET(GCC_COVERAGE_COMPILE_FLAGS "-lIrrlicht -lGL -lGLU -lXrandr -lXi -lXxf86vm -lGLEW")
SET(GCC_COVERAGE_COMPILE_INCLUDE "-std=c++11 -I ./include")
find_package(glfw3 3.1 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(X11)
add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
add_definitions(${GCC_COVERAGE_COMPILE_INCLUDE})
if (OPENGL_FOUND)
message("opengl found")
message("include dir: ${OPENGL_INCLUDE_DIR}")
message("link libraries: ${OPENGL_gl_LIBRARY}")
else (OPENGL_FOUND)
message("opengl not found")
endif()
FILE(GLOB SRCS src/*.cpp)
FILE(GLOB HDRS include/*.hpp)
ADD_EXECUTABLE(toto
${SRCS}
${HDRS}
)
TARGET_LINK_LIBRARIES(toto
"/usr/lib/libIrrlicht.a"
)
include_directories(${OPENGL_INCLUDE_DIR})
target_include_directories(toto PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(toto ${OPENGL_gl_LIBRARY} glfw)
target_link_libraries(toto ${OPENGL_glu_LIBRARY})
main.cpp
#include "my.hpp"
int main(int ac, char **av)
{
/* code */
printf("toto\n");
IrrlichtDevice *device =
createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return (0);
}
my.hpp
#ifndef IRRLICHT
#define IRRLICHT
#include <stdio.h>
#include <iostream>
#include <irr/irrlicht.h>
#include <cstdlib>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
#endif
I would like to have an executable but have have this error
[ 50%] Building CXX object CMakeFiles/toto.dir/src/main.cpp.o
[100%] Linking CXX executable toto
/usr/bin/ld: /usr/lib/libIrrlicht.a(CIrrDeviceLinux.o): référence au symbole non défini « XConvertSelection »
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO manquant dans la ligne de commande
collect2: error: ld returned 1 exit status
CMakeFiles/toto.dir/build.make:86 : la recette pour la cible « toto » a échouée
make[2]: *** [toto] Erreur 1
CMakeFiles/Makefile2:67 : la recette pour la cible « CMakeFiles/toto.dir/all » a échouée
make[1]: *** [CMakeFiles/toto.dir/all] Erreur 2
Makefile:83 : la recette pour la cible « all » a échouée
make: *** [all] Erreur 2
Your compiler says that you are missing a symbol XConvertSelection. I believe the compiler already gave you an answer:
/usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO manquant dans la ligne de commande
Searching for the error message, a very similar question has already been asked. Adding X11 to your list of libraries in CMakeLists.txt should fix your issue:
target_link_libraries(toto ${X11_LIBRARIES})
I was learning how to multithread in c++ and I run into this problem. I've searched the internet and didn't found a satisfactory answer.
I'm pretty sure the library's directory is included.
This are my system specifications:
Oracle Virtual box 5.2.12
Debian 9
Netbeans 8.2
gcc and g++ 6.3.0
This are the errors
Cannot find include file "/usr/include/c++/6".
unable to resolve identifier future.
unable to resolve identifier get.
This is my tutorials code:
// async example
#include <iostream> // std::cout
#include <future> // std::async, std::future
// a non-optimized way of checking for prime numbers:
bool is_prime (int x) {
std::cout << "Calculating. Please, wait...\n";
for (int i=2; i<x; ++i) if (x%i==0) return false;
return true;
}
int main ()
{
// call is_prime(313222313) asynchronously:
std::future<bool> fut = std::async (is_prime,313222313);
std::cout << "Checking whether 313222313 is prime.\n";
// ...
bool ret = fut.get(); // waits for is_prime to return
if (ret) std::cout << "It is prime!\n";
else std::cout << "It is not prime.\n";
return 0;
}
And this is the building output:
cd '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/asynctutorial
make[2]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -include /usr/include/c++/6.3.0 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
cc1plus: fatal error: /usr/include/c++/6.3.0: No existe el fichero o el directorio
compilation terminated.
nbproject/Makefile-Debug.mk:66: fallo en las instrucciones para el objetivo 'build/Debug/GNU-Linux/main.o'
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-Debug.mk:59: fallo en las instrucciones para el objetivo '.build-conf'
make[1]: *** [.build-conf] Error 2
make[1]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-impl.mk:39: fallo en las instrucciones para el objetivo '.build-impl'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 323ms)
You need the -pthread option in your compiler flags.
Example:
➜ g++ -std=c++11 -pthread async.cpp
➜ ./a.out
Checking whether 313222313 is prime.
Calculating. Please, wait...
It is prime!
I am programming in ARduino and I am try to connect Arduino with C++. I have the folowing function:
//Prueba.cpp
#include <iostream>
#include <SerialStream.h>
#include "/usr/local/lib/libserial.so.0.0.0"
using namespace std;
using namespace LibSerial;
int main() {
SerialStream my_serial_stream;
my_serial_stream.Open("/dev/ttyACM0");
my_serial_stream.SetBaudRate(SerialStreamBuf::BAUD_9600);
my_serial_stream << "a0" << endl;
return 0;
}
But when I exeute it, give me a lot of error with like this.
usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\377’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\17’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\37’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\200’ parásito en el programa
In file included from Prueba.cpp:11:0:
/usr/local/lib/libserial.so.0.0.0:99:914: aviso: caracter(es) nulo(s) ignorados [activado por defecto]
In file included from Prueba.cpp:11:0:
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\205’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\355’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\17’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\204’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\351’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\376’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\377’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\377’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\277’ parásito en el programa
/usr/local/lib/libserial.so.0.0.0:99:1: error: ‘\20’ parásito en el programa
Anyone know hay this happend? I installed libserial with sudo apt-get install libserdial-dev but nothing.
I suppose that this might help you in general: this
I have a weird problem trying to link a simple code which use a personal library which uses lib4cplus.
The file with the main code is so easy and doesn't use log4cplus. I only use lib4cplus into the library. The library compiles correctly but when i link the main file with the library it thowrs errors like that (loggers var not defined under architecture x86_64)
g++ leer.cpp -c
ar r libfichero.a blowfish.o clase.o
g++ -o Class leer.o -lm -lz -llog4cplus libfichero.a
Undefined symbols for architecture x86_64:
"fichero::loggerFichero", referenced from:
fichero::startLoggers() in libfichero.a(clase.o)
fichero::fichero()in libfichero.a(clase.o)
fichero::fichero()in libfichero.a(clase.o)
"fichero::errorLoggerFichero", referenced from:
fichero::startLoggers() in libfichero.a(clase.o)
fichero::fichero()in libfichero.a(clase.o)
fichero::fichero()in libfichero.a(clase.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [all] Error 1
make: *** [p21] Error 2
The errors comes when i want to define my private logger vars (ficheroLogger and errorFicheroLogger).
That's the code in the cpp file of my library.
bool fichero::startLoggers()
{
// Aquí inico los loggers que voy a usar en la clase.
loggerFichero = Logger::getInstance(LOG4CPLUS_TEXT("utils"));
errorLoggerFichero = Logger::getInstance("BigFail");
}
// Método para definir los logs.
bool fichero::initLogFichero()
{
cout << "Entering LOG Config part..." << endl;
LogLog::getLogLog()->setInternalDebugging(true);
Logger root = Logger::getRoot();
// Load the properties
PropertyConfigurator::doConfigure("ficheroLog4cplus.properties");
Logger fileLog = Logger::getInstance(LOG4CPLUS_TEXT("filelogger"));
// Log with INFO level
LOG4CPLUS_INFO(fileLog, "Application startup");
cout << "Exiting the main part()..." << endl;
// Log with INFO level
if (fileLog.isEnabledFor(INFO_LOG_LEVEL))
{
LOG4CPLUS_WARN(fileLog, "Application shutdown");
}
startLoggers();
return true;
}
// Constructor y Destructor
fichero::fichero()
{
nomFile = "file.txt";
delimitador = "";
hayDelimiatador = false;
initLogFichero();
LOG4CPLUS_WARN(loggerFichero, "Inicio normal");
LOG4CPLUS_WARN(errorLoggerFichero, "Inicio error.");
}
This does not look a like a problem of log4cplus. Try to reshuffle the command line:
g++ -o Class leer.o libfichero.a -llog4cplus -lz -lm
I'm trying to set-up a function, using the ffmpeg c api, to re-sample a stream (AVStream format) to fixed (1channel - u8 sample) format.
I'm using ffmpeg libswresample library, but when I try to compile, I get a linker error that is strictly connected to swresample functions.
Let me post the code:
double *resample8(AVFrame *frame, int size, AVCodec* codec){
/* initialization of the output array */
double *out = new double[size];
/* create resampling context */
struct SwrContext *resampleContext;
resampleContext = swr_alloc();
if (!resampleContext) {
fprintf(stderr, "Could not allocate resampler context\n");
return NULL;
}
/* set options */
av_opt_set_int(resampleContext, "in_channel_layout", *(codec->channel_layouts), 0);
av_opt_set_sample_fmt(resampleContext, "in_sample_fmt", *(codec->sample_fmts), 0);
av_opt_set_int(resampleContext, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
av_opt_set_sample_fmt(resampleContext, "out_sample_fmt", AV_SAMPLE_FMT_U8, 0);
/* initialize the resampling context */
if (swr_init(resampleContext) < 0) {
fprintf(stderr, "Failed to initialize the resampling context\n");
return NULL;
}
return NULL;
}
Here is the inclusion:
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/opt.h>
#include <libavutil/channel_layout.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#ifdef __cplusplus
} // end extern "C".
#endif // __cplusplus
And here is the error I get, compiling with netbeans, g++
(additional g++ commands: -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/audiosync
make[2]: ingresso nella directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/audiosync build/Debug/GNU-Linux-x86/dataReader.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/tansforms.o build/Debug/GNU-Linux-x86/tognuplot.o -lavcodec -lavformat -lavutil -lswresample -lfftw3 -lm
build/Debug/GNU-Linux-x86/dataReader.o: nella funzione "resample8(AVFrame*, int, AVCodec*)":
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:285: riferimento non definito a "av_opt_set_sample_fmt"
/home/davide/Documenti/Tesi/audiosync-fin/audiosync/dataReader.cpp:288: riferimento non definito a "av_opt_set_sample_fmt"
/usr/local/lib/libswresample.so: riferimento non definito a "av_calloc#LIBAVUTIL_54"
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:65: set di istruzioni per l'obiettivo "dist/Debug/GNU-Linux-x86/audiosync" non riuscito
make[2]: *** [dist/Debug/GNU-Linux-x86/audiosync] Errore 1
make[2]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-Debug.mk:62: set di istruzioni per l'obiettivo ".build-conf" non riuscito
make[1]: *** [.build-conf] Errore 2
make[1]: uscita dalla directory "/home/davide/Documenti/Tesi/audiosync-fin/audiosync"
nbproject/Makefile-impl.mk:39: set di istruzioni per l'obiettivo ".build-impl" non riuscito
make: *** [.build-impl] Errore 2
BUILD FAILED (exit value 2, total time: 5s)
here is the linker configuration linker config
I searched for any clue about the linker error, and I found that it could be caused by multiple versions of ffmpeg installed. I removed ubuntu (I'm using 15.04) base installation of ffmpeg and installed ffmpeg 2.7.2 from the tar downloaded by ffmpeg.org
I can't seem to find a solution at the moment, can anyone help?
I think the linking order matters
refer this question
Why does the order in which libraries are linked sometimes cause errors in GCC?
Try this order
libavdevice libavformat libavfilter libavcodec libwscale libavutil libswresample libswscale libpostproc libavresample