I real need help over here, I have to do this ASCIITwitter project for an university's exam and I'm stucked with this problem:
I have to add a header file and a source file on my project of course, so first I tried some easy code to see if I'm capable to do this.
Just a program to do some square operations:
There's my code:
Twitter.h
#ifndef TWITTER_H_
#define TWITTER_H_
int square(int);
#endif /* TWITTER_H_ */
Twitter.c
#include "Twitter.h"
int square(int x)
{
return x*x;
}
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Twitter.h"
int main(void)
{
int y;
y=square(5);
printf("%d\n",y);
system("PAUSE");
}
But it give to me "undefined reference to 'square' and I really don't know how to fix this. I've tried searching on internet, but I'm working on windows, I don't have any makefile, I just want to make this work. Please help me.
Related
I am starting a new project on a STM32L476 Nucleo board and planned to use FreeRTOS.
My initial project structure:
main.c
#include "project.h"
int main(void)
{
/* Configure the system clock */
Clock_Config();
/* Configure IOs */
GPIO_Config();
/* FreeRTOS Stuff */
NVIC_SetPriorityGrouping(3);
vTaskStartScheduler();
/* Should never get here! */
while (1){}
}
project.h
#ifndef PROJECT_H_
#define PROJECT_H_
/* MPU Files */
#include "stm32l4xx.h"
/* Project Files */
#include "gpio.h"
#include "clock.h"
/* FreeRTOS */
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
#define TASKPRIO_STD ( tskIDLE_PRIORITY + 1 )
#define TICK_TASK_PERIOD_MS pdMS_TO_TICKS( 500 )
#endif /* PROJECT_H_ */
project.c
#include "project.h"
static void vSerialTask( void * pvParameters );
xTaskCreate( vSerialTask, "I2C", configMINIMAL_STACK_SIZE, NULL, TASKPRIO_STD, NULL);
static void vSerialTask( void *pvParameters ){
for( ;; )
{
}
}
I get a syntax error with this structure in xTaskCreate line: expected ')' before string constant
If I move xTaskCreate to my main.c and leave the task itself in my project.c (also have to delete static in this case) my project compiles successfully.
What is the problem here? I already saw working projects where xTaskCreate is not done within main.c so can't imagine this is the real problem?
You can't call the function outside another function and it is exactly what you try to do.
You can only call functions from another functions. The first function executed is main
I am using ICU lib for Exemplar, I am getting undefined ref for `ulocdata_open_63'
I am not using "ulocdata_open_63" function but "ulocdata_open". Library is linked properly.
Why it is looking for ulocdata_open_63 definition even though I am not calling it.
Sample code:-
#include <stdio.h>
#define UNICODE
#include <unicode/uloc.h>
#include <unicode/ulocdata.h>
#include <unicode/urename.h>
typedef unsigned short U16;
int main()
{
char localeID[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY] = "en_US";
UErrorCode icuStatus = U_ZERO_ERROR;
ULocaleData* uld = ulocdata_open("en", &icuStatus);
...
}
It looks you're linking against a ICU library that was built with ICU version suffixes, which is the default. To build a library without version suffixes you'll have to add the flag --disable-renaming to the configure build step of ICU4C.
See https://unicode-org.github.io/icu/userguide/icu4c/build.html#icu-as-a-system-level-library.
I am using CGAL 4.12 and eigen 3.3.4 and trying to compile the Poisson_surface_reconstruction_3 example trough a Matlab mex function and am getting the following error:
C:\Users\u0116401\Documents\PRosPeRoS\Matlab_Code\mexTest\CGAL_poisson_reconstruction.cpp(70): error C2039: 'make_normal_of_point_with_normal_pmap': is not a member of 'CGAL'
C:\dev\CGAL-4.12\include\CGAL/IO/read_xyz_points.h(40): note: see declaration of 'CGAL'
C:\Users\u0116401\Documents\PRosPeRoS\Matlab_Code\mexTest\CGAL_poisson_reconstruction.cpp(70): error C3861: 'make_normal_of_point_with_normal_pmap': identifier not found
It seems 'make_normal_of_point_with_normal_pmap' can't be found. Does anyone know what is causing this issue?
The code that produces this error is:
/* mex headers */
#include <mex.h>
/* C++ headers */
#include <vector>
#include <fstream>
/* CGAL headers */
#include <CGAL/trace.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
#include <CGAL/IO/output_surface_facets_to_polyhedron.h>
#include <CGAL/Poisson_reconstruction_function.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
// Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef Kernel::Sphere_3 Sphere;
typedef std::vector<Point_with_normal> PointList;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Poisson_reconstruction_function<Kernel>Poisson_reconstruction_function;
typedef CGAL::Surface_mesh_default_triangulation_3 STr;
typedef CGAL::Surface_mesh_complex_2_in_triangulation_3<STr> C2t3;
typedef CGAL::Implicit_surface_3<Kernel, Poisson_reconstruction_function> Surface_3;
void mexFunction(int nlhs, mxArray *plhs[], /*Output variables */
int nrhs, const mxArray *prhs[]) /*Input variables */
{
PointList points;
std::ifstream stream("kitten.xyz");
if (!stream ||
!CGAL::read_xyz_points_and_normals(
stream,
std::back_inserter(points),
CGAL::make_normal_of_point_with_normal_pmap(std::back_inserter(points))))
}
The function is named make_normal_of_point_with_normal_map() (map not pmap) and it takes Point_with_normal as parameter. The call should be:
CGAL::make_normal_of_point_with_normal_map(Point_with_normal())
Iam confused with the below question I did the program as per my understanding but it crashes what am I doing wrong? If someone can please assist me it would be much appreciated.
my main.cpp looks like this:
#include <iostream>
#include <iomanip>
#include "Number.h"
using namespace std;
int main()
{
Number n1(10);
Number n2 = n1;
n2.printNum();
n2.addOne();
n1 = n2;
n1.printNum();
return 0;
}
Then my header file looks like this:
#include <iostream>
using namespace std;
class Number
{
int *p;
public:
Number(int);
void addOne();
void printNum();
};
And the below parts for the constructor I need to complete there where it shows comments that's the part I should complete:
#include <iostream>
#include "Number.h"
using namespace std;
Number::Number(int a1)
{
*p = a1;//write the code needed to initialise the value of the member variable with a1
}
void Number::printNum()
{
cout << "The number is " << *p << endl;
}
void Number::addOne()
{
*p++;//write the code needed to increment the value of the member variable by one.
}
Then the question asks the below what should I do to the code to use the BIG THREE?
Consider the following program. Complete the class definition (where you are asked to) and check the output. You can see that that program works without error once it is completed. However, experts suggest that in any class that uses pointers and the new operator it is better to follow the rule of The Big Three. Modify the class definition to follow the rule of The Big Three and submit the new program and the output. Demonstrate the use of this pointer.
Thank you
Rohan
The below code can be compiled and run, but VS2015 intellisense shows error. g++ & eclipse has the same issue (compiled & run but shows error)
Does anyone know how to fix it? I tried searching on google but hopeless.
The error is a little annoying.. :-)
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
using namespace std::literals;
using namespace chrono_literals;
int main()
{
this_thread::sleep_for(5s);
cout << "test \n";
return 0;
}
Error message: "Invalid suffix 's' on integer literal"
Thanks a lot!
You should add some #include statements and namespace references:
#include <iostream>
#include <chrono>
#include <thread>
int main()
{
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for(5s);
std::cout << "test \n";
return 0;
}
In your code, the compiler is not been told to use namespace std. The 5s does not work without std::literals