This is my code:
#include <eigen3/Eigen/Geometry>
#include <stdio.h>
int main(){
Eigen::Matrix3Xd in(3, 100, 100), out(30, 100, 0);
Eigen::Affine3d A;
A = Find3DAffineTransform(in,out);
return 0;
}
and I am using the functions provided by wiki:
https://github.com/oleg-alexandrov/projects/blob/master/eigen/Kabsch.cpp#L4
Basically, I was trying to get the rotation matrix based on the input and output points given.
And this the error I got:
Well, from your code it does not seem that you are actually using this code from github.
You should either copy-paste the contents of Kabsch.cpp to your application above main (this is a quick'n'dirty solution), or you should:
Add Kabsch.cpp to your build (meaning it should be compiled and linked with your main file
Forward declare Find3DAffineTransform function above your main (or put the declaration in a separate hpp file and include it from your main file
Related
I have been searching online for solutions to this rather simple problem. My goal is to call a function from a separate .cpp file in my main.cpp file. What I have found thus far has told me to define my function in a separate .cpp file (averageScore.cpp) which looks like:
void averageScore()
{
"Blah, Blah, Blah"
}
And then declare the function as a prototype in a header file (Lesson1.h) which looks like:
#include "C:/averagescore.cpp"
void averageScore();
And finally call the function again in the main.cpp:
#include "Lesson1.h"
int main()
{
averageScore();
return 0;
}
I am currently a CS student and my overall objective with this method of organization and execution is to create a single project for all of the rudimentary programs we must create on a weekly basis instead of creating a new project for every single program. For reference, I am using VScode and have used the following link to help me thus far:
http://www.cplusplus.com/forum/beginner/97779/
My condolences and gratitude are extended to anyone who has taken the time to read through this and help me out!
To achieve what you want, you must create a header file, and declare your function there, for example:
lesson1.h
void averageScore();
In a .cpp file, you define that function and include the header you just created:
lesson1.cpp
#include "lesson1.h"
void averageScore(){
// Do what you want in this function
}
Then you can call that function in your main.cpp by including "lesson1.h":
main.cpp
#include "lesson1.h"
int main()
{
averageScore();
return 0;
}
I have been recently practicing managing multiple objects and drawing them in C++ using SFML library. I wanted my textures and future resources to be more reusable so I decided to make use of Thor library which suits my needs really well.
So I've written first few lines of code based on what you can find in this tutorial and the compiler always says:
main.cpp|12|error: 'textures_holder' does not name a type
This line gives an error :
textures_holder.acquire("Dirt", thor::Resources::fromFile<sf::Texture>("Textures\\dirt_block.png"));
I'm using Code::Blocks IDE with MinGW compiler and SFML 2.5.0.
Here's my main.cpp and the header file which contains extern object :
//...
#include <Thor/Resources.hpp>
#include "Dirt_Block.h"
using namespace std;
//Adding textures to the texture library
//THIS LINE GIVES AN ERROR
textures_holder.acquire("Dirt", thor::Resources::fromFile<sf::Texture>("Textures\\dirt_block.png"));
//Rest of code...
Dirt_Block.h (only the upper part) :
#ifndef DIRT_BLOCK_H
#define DIRT_BLOCK_H
#include <SFML\Graphics.hpp>
#include <vector>
#include <Thor/Resources.hpp>
#include <Thor/Resources/SfmlLoaders.hpp>
extern sf::Vector2u screenRes;
extern thor::ResourceHolder<sf::Texture, std::string> textures_holder;
//Rest of the code
I'd like to know what is causing this error and maybe help others who may experience similiar frustrating problems. Thanks for help.
EDIT :
As suggested in the comment I've declared a few extern int variables in the Dirt_Block.h so now it looks like this :
//...
extern int test_int_up;
extern sf::Vector2u screenRes;
extern thor::ResourceHolder<sf::Texture, std::string> textures_holder;
extern int test_int_d;
//...
And then assinged to them some value in main.cpp :
//...
test_int_up = 55;
test_int_d = 55;
//Adding textures to the texture library
textures_holder.acquire("Dirt", thor::Resources::fromFile<sf::Texture>("Textures\\dirt_block.png"));
//...
But the compiler gives error :
main.cpp|9|error: 'test_int_up' does not name a type
main.cpp|10|error: 'test_int_d' does not name a type
main.cpp|12|error: 'textures_holder' does not name a type
Much less distracting to see what your problem is without all the extraneous code!
C++ programs don't start from the top of the file and run code down to the bottom. They start at the main(), and control flow proceeds from there, with one thing triggering another.
(Note: That doesn't take into account global constructor ordering, which does go in order of declaration--but you have no guarantee of the order declarations from "different files" might run in.)
Point being, you can't just make random function or method calls in the middle of a file. That's where you put declarations. You have to be inside of a function or method to make calls, e.g.
int main() {
textures_holder.acquire(
"Dirt",
thor::Resources::fromFile<sf::Texture>("Textures\\dirt_block.png")
);
...
}
I had a function to get points inside a 3D arc working inside a file but, trying to order the code into the appropriate folders, I broke it, and I don't know why because I think I am including it correctly.
Originally a lot of calculations were inside a file "messages.cpp", but it is supposed to have just the messages and the calculations should be in Calculations folder.
So now messages.cpp is something like this:
#include "../../FGProcessorModule/Calculations/ArcToPoints.h"
namespace myNamespace {
void MsgProvider::onEvent{
std::vector<Formulas::LLPoint> allPoints = ArcToPoints(center, start, end);
}
}
In "../../FGProcessorModule/Calculations/ArcToPoints.h" I have:
#ifndef ARCTOPOINTS_H
#define ARCTOPOINTS_H
#include blablabla
namespace myNamespace{
std::vector<Formulas::LLPoint> ArcToPoints (Formulas::LLPoint, Formulas::LLPoint, Formulas::LLPoint);
}
#endif /* ARCTOPOINTS_H */
And finally in "../../FGProcessorModule/Calculations/ArcToPoints.cpp" I have:
#include "ArcToPoints.h"
namespace myNamespace{
std::vector<Formulas::LLPoint> ArcToPoints (Formulas::LLPoint center, Formulas::LLPoint start, Formulas::LLPoint end){
//Lots of calculations
}
}
I think everything is OK but I receive this error when I want to compile:
undefined reference to `FVIS::ArcToPoints(Formulas::LLPoint,
Formulas::LLPoint, Formulas::LLPoint)'
I don't know if this will help others as it is a very specific problem, this is a project using ros and catkin.
I was missing including the new created file in CMakeLists.txt. Now it compiled just fine.
I have a class called File that is defined (along with other classes) in the header "dmanager1.h". In the "dmanager1.cpp" file (implementation for the dmanager1.h file), when I list the headers in one order I get an error when trying to compile along with my main.cpp (main.cpp is empty except for the header call and an empty "int main()"...basically I'm just testing the class .h and .cpp files)... If I switch the headers around in the dmanager1.cpp file I get no errors. I don't understand what is happening. The error I'm getting is:
error: 'File' does not name a type
I get said error when I have my header's ordered in my "dmanager1.cpp" as follows:
#include "dmanager1.h"
#include <iostream>
#include <cstring>
If I switch the header's around to:
#include <iostream>
#include <cstring>
#include "dmanager1.h"
...I don't get the compilation error. Is the first order getting parsed funny? Any thoughts would be greatly appreciated.
EDIT: Added part of the header in question...
#ifndef _dmanager1_h
#define _dmanager1_h
//--------------------
// Forward References
//--------------------
// Node_L, Node_T, and Sector are defined in File: dmanager1a.h
class Node_L;
class Node_T;
class Sector;
class File
{
public:
// Default Constructor
//File();
// Constructor: Allowing "name", "size", and/or "permissions" to be set
// Permissions set to default of 0 == read and write
File(const char * & name, float size = 0, int permissions = 0) : timestamp(11223333) {};
// Default Destructor
~File();
//returns an int corresponding to the date modified (mmddyy)
int get_date_mod(void) const {return timestamp;}
// Return's current level of permission on the File: 0 = read/write, 1 = read only
int get_permission(void) const {return permission;}
// Set's Permission to "level": 0 = read/write, 1 = read only
int set_permission(int level);
private:
// Data members
char * name;
float size_OA;
//function used to update "date modified"
void update_timestamp(void);
// Current permission level of the file: 0 = read/write, 1 = read only
int permission;
//value modified by update_timestamp() and the value returned by get_date_mod(). Date file last edited.
int timestamp;
};
Most likely your dmanager1.h header needs something that iostream or cstring define.
As a result, it doesn't get parsed correctly, and the compiler doesn't understand the declaration of your File class.
If you post your dmanager1.h file, you'll be able to get a more detailed answer.
Make sure that each of your headers is completely self-sufficient. It needs to #include headers for everything that it uses and not assume that they will be included by something else. Every header should work even if it is the only header that a .c file includes.
I'm betting that your dmanager1.h header is using something from the standard library and you aren't including the header that it needs. Swapping the header appears to fix the problem, but it's only working by coincidence.
One diagnostic test you can do is to create a .c file that contains nothing but the line #include "dmanager1.h". Try to compile it. If the compiler throws an error, it should provide hints as to which additional headers need to be included.
Update: I can compile using the initial portion of the header that you posted using g++ -Wall and I get no errors or warnings at all. Please post a sample that reproduces the problem.
I have a code that proceses frames in each iteration and generatesa matrix. My final goal is to send the matrix data to matlab in order to examine the evolution of the matrix with each frame.
In order to achieve this I defined a static variable Engine in a header file (helper.h).
#include "engine.h";
#include "mex.h";
static Engine *engine;
In the main() program I open the engine only once:
#include helper.h
main(){
if (!(engine = engOpen(NULL))) {
MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine",(LPSTR) "pcTest.cpp", MB_OK);
exit(-1);}
//here comes frame processing using a while loop
.
. //a function is called (defined in matrix.cpp)
.
//frame processing ends
}
And inside matrix.cpp is where I get the matrix I want to send to Matlab Engine, so I do something like this:
#include helper.h
mxArray *mat;
mat = mxCreateDoubleMatrix(13, 13, mxREAL);
memcpy(mxGetPr(mat),matrix.data, 13*13*sizeof(double));
engPutVariable(engine, "mat", mat);
I want to use the pointer to engine the most efficient way. I am a bit conffused about how to correctly use matlab engine.
Any help woould be welcomed, because the matlab documentation and examples didn't help at all as they have all the code in the same file and they don't use iterations. Thanks in advance.
EDIT
First problem solved about the engine pointer. The solution is declaring it as extern.
#include "engine.h";
#include "mex.h";
extern Engine *engine;
and in main.cpp
#include helper.h
Engine *engine=NULL;
main(){}
static means "local to the current compilation unit". A compilation unit is normally a single .cpp file, so you have two engine variables in your program, one in main.o and one in matrix.o. You need to declare engine as extern in the header file and define it without any modificator in exactly one .cpp file.
helper.h:
extern Engine* engine;
main.cpp:
#include "helper.h"
Engine* engine = NULL;