Error on compiling c file on MPLAB X ide - c

I get following errors when trying compile using MPLAB X on Windows..
newmain.c:40:9: error: unknown configuration setting: 'JTAGEN'
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
newmain.c:62:2: error: 'TRISA' undeclared (first use in this function)
newmain.c:61:2: error: 'LATA' undeclared (first use in this function)
I tried this on 2 different machines (on Windows 8.1 and Vista), but they all gave me same error.
It seemed like that xc.h file is already included to project since I can open that file. And also I googled for this problem but there wasn't a solution for this.
Thank you very much if you can give me a possible way to solve this.
I also attached photo describing project properties ​for this project.
Following is full description of error :
- CLEAN SUCCESSFUL (total time: 52ms) make -f
nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]:
Entering directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' make -f
nbproject/Makefile-default.mk
dist/default/production/Lab01.X.production.hex make[2]: Entering
directory 'Z:/Personal Data/MPLABXProjects/Lab01.X' "Z:\Program Files
(x86)\Microchip\xc32\v1.40\bin\xc32-gcc.exe" -g -x c -c
-mprocessor=32MX340F512H -MMD -MF build/default/production/newmain.o.d -o
build/default/production/newmain.o newmain.c newmain.c:40:9: error:
unknown configuration setting: 'JTAGEN' #pragma config JTAGEN = OFF
// JTAG Enable OFF (only use for '250)
nbproject/Makefile-default.mk:105: recipe for target
'build/default/production/newmain.o' failed ^ newmain.c: In function
'main': make[2]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' newmain.c:61:2: error: 'LATA' undeclared
(first use in this function) nbproject/Makefile-default.mk:78: recipe
for target '.build-conf' failed LATA = 0; // Set value of PORT A
output to 0. ^ make[1]: Leaving directory 'Z:/Personal
Data/MPLABXProjects/Lab01.X' nbproject/Makefile-impl.mk:39: recipe
for target '.build-impl' failed newmain.c:61:2: note: each undeclared
identifier is reported only once for each function it appears in
newmain.c:62:2: error: 'TRISA' undeclared (first use in this
function) TRISA = 0; // Set all pins on PORT A to output ^ make[2]:
*** [build/default/production/newmain.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED
(exit value 2, total time: 203ms)
And source is
#include <xc.h>
#pragma config FWDTEN = OFF, JTAGEN = OFF
void delay(void);
unsigned int ctr = 0;
unsigned int delayVal = 2048;
int main(void)
{
LATA = 0;
TRISA = 0xFF00;
while(1)
{
LATA = 0x0055;
delay();
LATA = 0x00AA;
delay();
ctr++;
}
}
void delay(void)
{
unsigned int i,j;
for (i = 0; i < delayVal; i++)
{
for (j = 0; j < 20; j++);
}
}

The errors you receive indicate that the compiler does not see any libraries to reference those registers to. It treats them as regular variables instead.
You should include the specific header file for the processor you are using and also check to see what registers are structured in there to make more sense of your problem.

Related

Linux RT-Unable to link .lib to VSCode-Undefined reference to `DAQmxCreateTask'

I was trying to cross compile a C code with CMake inside Linux RT using VSCode. But I am encountering an error due to the mistake in linking (.so) file with project. I have gone through many solutions but failed to run the task. My code is given below:
#include<stdio.h>
#include"/home/admin/helloworld/src/NIDAQmx.h"
TaskHandle taskHandle=0;
int ret=0;
void main()
{
printf("Hello world");
ret=DAQmxCreateTask("task",&taskHandle);
printf("Return for creating task is %d\n",ret);
DAQmxStopTask (taskHandle);
DAQmxClearTask(taskHandle);
printf("Task closed ");
}
Error while running the task.
[ 50%] Linking C executable bin/helloWorld
CMakeFiles/helloWorld.dir/home/admin/helloworld/src/helloWorld.c.o:
In function `main':/home/admin/helloworld/src/helloWorld.c:11: undefined reference to `DAQmxCreateTask'
/home/admin/helloworld/src/helloWorld.c:13: undefined reference to `DAQmxStopTask'
/home/admin/helloworld/src/helloWorld.c:14: undefined reference to `DAQmxClearTask'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloWorld.dir/build.make:95: bin/helloWorld] Error 1
make[1]: *** [CMakeFiles/Makefile2:68:CMakeFiles/helloWorld.dir/all] Error 2
* The terminal process
"/bin/bash '-c', 'make'" failed to launch
(exit code: 2).
* Terminal will be reused by tasks, press any key to close it.
I modified my CMakeLists.txt as follows:
cmake_minimum_required(VERSION 3.7.2)
# project settings
project(helloWorld VERSION 0.1.0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
set(CMAKE_GENERATOR "Unix Makefiles")
# executable settings
add_executable(helloWorld ../src/helloWorld.c)
set(CMAKE_BUILD_TYPE Debug)
LINK_LIBRARIES(NIDAQmx ../src/libnidaqmx.so)
If I remove the elements associated with NIDAQmx code working properly.

Why does a function declared and included using header file show as undefined?

I have the following code in my files and all of these are in the same directory:
readMake.c:
#include <stdio.h>
#include "my_make.h"
int main(int argc, char* argv[]) {
printSomething();
}
printer.c:
#include <stdio.h>
int printSomething(){
printf("printed\n");
return 1;
}
my_make.h:
int printSomething();
However, when I try to compile and run my code, I get the following error:
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/prob1.dir/readMake.c.o: in function `main':
/cygdrive/c/Users/harsh/OneDrive/Documents/CSC352/assg9/prob1/readMake.c:5: undefined reference to `printSomething'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/prob1.dir/build.make:93: prob1.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/prob1.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/prob1.dir/rule] Error 2
make: *** [Makefile:124: prob1] Error 2
My IDE shows the proper signature of the printSignature function and where it is declared in the header file when I hover over the call in main, but the compilation doesn't seem to be working. Why is this happening and how can I resolve this?
I figured out a solution specific to CLion, unloading the CMakeLists.txt file and then creating a new one seems to resolve the issue.
I had to do 'Tools>CMake>Unload'
and then create a new CMakeLists.txt file which was automatically done by clicking an option appearing at the top of the window and selecting all of the files from a list of checkboxes.

Attempting to load module, however when trying to compile the module the computer states that several structs are undefined

The purpose of this module is to basically do the same thing as what happens when you type into your linux command line cat /proc/buddyinfo
Code
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mmzone.h>
#define DRIVER_AUTHOR "Matthew James Barnes <mbarnes2k5#Gmail.com>"
#define DRIVER_DESC "A driver that does the same thing as /proc/buddyinfo"
/***
*GLOBAL VARIABLES
***/
extern struct pglist_data *first_online_pgdat(void);
extern struct pglist_data *next_online_pgdat(struct pglist_data*pgdat);
struct pglist_data *pgdat;
extern struct zone *zone;
int init_module(void)
{
int order;
for(pgdat = first_online_pgdat(); pgdat; pgdat = next_online_pgdat(pgdat))
{
for(zone = pgdat->node_zones; zone; zone = next_zone(zone)){
printk(KERN_INFO "Node %d, zone %8s ",pgdat->node_id, zone->name);
printk(KERN_INFO "Node %d", pgdat->node_id);
printk(KERN_CONT "Zone %s",zone->name);
for( order = 0; order < MAX_ORDER; ++order)
printk(KERN_CONT "%6lu ", zone->free_area[order].nr_free);
printk(KERN_CONT "\n");
}
}
return 0;
}
void cleanup_module(void){
printk(KERN_INFO "Zones have been feenished.\n");
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
~
~
~
~
~
~
~
I decided to go lean and create a makefile as well as a folder within my kernel called module-edits.
In module edits when I run the makefile, I run into a compilation error.
The command line returns the following:
make -C /lib/modules/5.4.0-26-generic/build M=/usr/local/share/source_code/version1/module-edits modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-26-generic'
Building modules, stage 2.
MODPOST 1 modules
ERROR: "next_online_pgdat" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "next_zone" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "zone" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "first_online_pgdat" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
make[2]: [scripts/Makefile.modpost:94: __modpost] Error 1
make[1]: [Makefile:1632: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-26-generic'
make: [makefile:5: all] Error 2
Now, what is baffling about this is that when I typed
#include <linux/mmzone.h>
there are a number of structs.
pgdat is a struct that allows access to the current page data.
*first_online_pgdat(void); is a function that points to the first page.
*next_online_pgdat(struct pglist_data*pgdat); points to the next page.
struct pglist_data *pgdat;
is basically the representation of my page.
and extern struct zone *zone is the representation of the zone type of the pages.
All of this is included in mmzone, but it's as if the functions in mmzone.h are not even being referenced.
I don't really understand what is going on, but I would appreciate assistance from experienced linux programmers.

XC8 compiler error, 499, when passing a structure

I have been trying to compile a code. I am very new to XC8 compiler. I have the following code.
main.c
void main()
{
bmp280_t bmp280;
...
bmp280.dev_addr = 0x77;
init_check = bmp280_init(&bmp280);
....
}
bmp280.h
...
typedef struct {
struct bmp280_calib_param_t calib_param;/**<calibration data*/
uint8_t chip_id;/**< chip id of the sensor*/
uint8_t dev_addr;/**< device address of the sensor*/
uint8_t oversamp_temperature;/**< temperature over sampling*/
uint8_t oversamp_pressure;/**< pressure over sampling*/
BMP280_WR_FUNC_PTR;/**< bus write function pointer*/
BMP280_RD_FUNC_PTR;/**< bus read function pointer*/
}bmp280_t;
BMP280_RETURN_FUNCTION_TYPE bmp280_init(bmp280_t *temp_bmp280);
...
bmp280.c
static bmp280_t *p_bmp280;
BMP280_RETURN_FUNCTION_TYPE bmp280_init(bmp280_t *temp_bmp280)
{
/* variable used to return communication result*/
BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
uint8_t v_data_u8 = BMP280_INIT_VALUE;
p_bmp280 = temp_bmp280;/* assign BMP280 ptr */
/* read chip id */
com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
BMP280_CHIP_ID_REG, &v_data_u8,
BMP280_GEN_READ_WRITE_DATA_LENGTH);/* read Chip Id */
p_bmp280->chip_id = v_data_u8;
/* readout bmp280 calibparam structure */
com_rslt += bmp280_get_calib_param();
return com_rslt;
}
...
After executing this code, I am getting an error as
":0: error: (499) undefined symbol:
_bmp280_init(dist/default/production\FTS_basic.X.production.obj)
(908) exit status = 1
nbproject/Makefile-default.mk:279: recipe for target 'dist/default/production/FTS_basic.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/Abhi/MPLABXProjects/FTS_basic.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Abhi/MPLABXProjects/FTS_basic.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/FTS_basic.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 10s)
"
As I see, there are no typo. The naming is correct. I also hope structure is being passed correctly.
Is there anything new I need to take care in XC8 compiler?
This is for pic16f1618 microcontroller.
Makefile-impl.mk
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
# Project Name
PROJECTNAME=FTS_basic.X
# Active Configuration
DEFAULTCONF=default
CONF=${DEFAULTCONF}
# All Configurations
ALLCONFS=default
# build
.build-impl: .build-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
# clean
.clean-impl: .clean-pre
${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
# clobber
.clobber-impl: .clobber-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean
# all
.all-impl: .all-pre .depcheck-impl
${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build
# dependency checking support
.depcheck-impl:
# #echo "# This code depends on make tool being used" >.dep.inc
# #if [ -n "${MAKE_VERSION}" ]; then \
# echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
# echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
# echo "include \$${DEPFILES}" >>.dep.inc; \
# echo "endif" >>.dep.inc; \
# else \
# echo ".KEEP_STATE:" >>.dep.inc; \
# echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
# fi

Error compiling PJSIP on Ubuntu

I am trying to compile PJSIP 2.1 with Video support on Ubuntu but I get the following error when running 'make' :
In file included from ../src/pjmedia/ffmpeg_util.c:26:0:
../src/pjmedia/ffmpeg_util.h:50:12: warning: ‘enum CodecID’ declared inside parameter list [enabled by default]
enum CodecID *codec_id);
^
../src/pjmedia/ffmpeg_util.h:50:12: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
../src/pjmedia/ffmpeg_util.h:53:7: warning: ‘enum CodecID’ declared inside parameter list [enabled by default]
pjmedia_format_id *fmt_id);
^
../src/pjmedia/ffmpeg_util.c:65:18: error: field ‘codec_id’ has incomplete type
enum CodecID codec_id;
^
../src/pjmedia/ffmpeg_util.c:167:13: error: conflicting types for ‘pjmedia_format_id_to_CodecID’
pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
^
In file included from ../src/pjmedia/ffmpeg_util.c:26:0:
../src/pjmedia/ffmpeg_util.h:49:13: note: previous declaration of ‘pjmedia_format_id_to_CodecID’ was here
pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
^
../src/pjmedia/ffmpeg_util.c: In function ‘pjmedia_format_id_to_CodecID’:
../src/pjmedia/ffmpeg_util.c:173:35: warning: comparison between pointer and integer [enabled by default]
if (t->id==fmt_id && t->codec_id != PIX_FMT_NONE) {
^
../src/pjmedia/ffmpeg_util.c:174:6: error: dereferencing pointer to incomplete type
*codec_id = t->codec_id;
^
../src/pjmedia/ffmpeg_util.c:174:6: warning: statement with no effect [-Wunused-value]
../src/pjmedia/ffmpeg_util.c:179:5: error: dereferencing pointer to incomplete type
*codec_id = PIX_FMT_NONE;
^
../src/pjmedia/ffmpeg_util.c:179:5: warning: statement with no effect [-Wunused-value]
../src/pjmedia/ffmpeg_util.c: At top level:
../src/pjmedia/ffmpeg_util.c:183:55: error: parameter 1 (‘codec_id’) has incomplete type
pj_status_t CodecID_to_pjmedia_format_id(enum CodecID codec_id,
^
make[2]: *** [output/pjmedia-i686-pc-linux-gnu/ffmpeg_util.o] Error 1
make[2]: Leaving directory `/home/gboutmy/Downloads/pjproject-2.1.0/pjmedia/build'
make[1]: *** [pjmedia] Error 2
make[1]: Leaving directory `/home/gboutmy/Downloads/pjproject-2.1.0/pjmedia/build'
make: *** [all] Error 1
I have installed the required dependencies and have no idea what the problem is. Reading the error messages it looks like it comes from error in the PJSIP code?
EDIT : I renamed enum CodecID to enum AVCodecID according to Getting “field has incomplete type” and "conflicting types" but now i'm getting the following error :
../lib/libpjmedia-codec-i686-pc-linux-gnu.a(ffmpeg_vid_codecs.o): In function `ffmpeg_codec_encode_whole.isra.7':
ffmpeg_vid_codecs.c:(.text+0x1374): undefined reference to `avcodec_encode_video2'
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/pjmedia-test-i686-pc-linux-gnu] Error 1
make[2]: Leaving directory `/home/gboutmy/Downloads/pjproject-2.1.0/pjmedia/build'
make[1]: *** [pjmedia-test] Error 2
make[1]: Leaving directory `/home/gboutmy/Downloads/pjproject-2.1.0/pjmedia/build'
make: *** [all] Error 1
Seems that you miss libavcodec/avcodec.h and, most probably, also libavformat/avformat.h. This should be because ffmpeg include folder is not into gcc's list of directories to look for header files.
From your update seems that pjsip is building against a newer ffmpeg version that the one available in Ubuntu's repositories. As you've built it yourself, you can configure pjsip to use your version by running:
./configure --with-ffmpeg=<YOUR_FFMPEG_FOLDER>
or
#Copy all library ffmpeg library files into one folder
CFLAGS="-I<YOUR_FFMPEG_FOLDER>" LDFLAGS="-L<YOUR_FFMPEG_LIB_FOLDER>" ./configure
The answer to the original question :
While compiling PJSIP I find that CodecID enum has been deprecated from ffmpeg. However it's been replaced by AV_CodecID and also the enum values have a leading AV_ added to them.
Thus after changing CodecID to AV_CodecID, please change the enums in ffmpeg_util.c.
For example this is what the table looks like after the change :
/* Conversion table between pjmedia_format_id and CodecID */
static const struct ffmpeg_codec_table_t
{
pjmedia_format_id id;
enum AVCodecID codec_id;
} ffmpeg_codec_table[] =
{
{PJMEDIA_FORMAT_H261, AV_CODEC_ID_H261},
{PJMEDIA_FORMAT_H263, AV_CODEC_ID_H263},
{PJMEDIA_FORMAT_H263P, AV_CODEC_ID_H263P},
{PJMEDIA_FORMAT_H264, AV_CODEC_ID_H264},
{PJMEDIA_FORMAT_MPEG1VIDEO, AV_CODEC_ID_MPEG1VIDEO},
{PJMEDIA_FORMAT_MPEG2VIDEO, AV_CODEC_ID_MPEG2VIDEO},
{PJMEDIA_FORMAT_MPEG4, AV_CODEC_ID_MPEG4},
{PJMEDIA_FORMAT_MJPEG, AV_CODEC_ID_MJPEG}
};

Resources