XC8 compiler error, 499, when passing a structure - c

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

Related

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.

How to properly use __delay_ms() in libraries in MICROCHIP XC8?

I'm facing some trouble trying to create a library that calls "__delay_ms()" inside a function. Made extensive search but couldn't find the solution, nor some other explanations. I'm using XC8 v2.30 MPLAB 5.45.
I have a main function that includes the header "qc3.h":
#include <xc.h> // include standard header file
// set Config bits
#pragma config FOSC=INTOSC, PLLEN=OFF, WDTE=OFF, MCLRE=ON,
#pragma config CLKOUTEN=OFF, IESO=OFF, FCMEN=OFF,CP=OFF, CPD=OFF,BOREN=OFF
#pragma config WRT=OFF,STVREN=ON,BORV=LO,LVP=OFF
// Definitions
#define _XTAL_FREQ 500000 // this is used by the __delay_ms(xx) and __delay_us(xx) functions
#include "qc3.h"
#define LED PORTAbits.RA2
//**********************************************************************************
//***************** main routine ***********************************************
//**********************************************************************************
void main ( )
{
// set up oscillator control register
OSCCONbits.SPLLEN=0; // PLL is disabled
OSCCONbits.IRCF=0x07; //set OSCCON IRCF bits to select OSC frequency=500Khz
OSCCONbits.SCS=0x02; //set the SCS bits to select internal oscillator block
// OSCON should be 0x7Ah now.
// Set up I/O pins
ANSELAbits.ANSELA=0; // set all analog pins to digital I/O
ADCON0bits.ADON=0; // turn ADC off
DACCON0bits.DACEN=0; // turn DAC off
// PORT A Assignments (0 = OUTPUT, 1 = INPUT)
TRISAbits.TRISA0 = 0; // RA0 = nc
TRISAbits.TRISA1 = 0; // RA1 = nc
TRISAbits.TRISA2 = 0; // RA2 = nc
TRISAbits.TRISA3 = 0; // RA3 = nc (MCLR)
TRISAbits.TRISA4 = 0; // RA4 = nc
TRISAbits.TRISA5 = 0; // RA5 = nc
QC3_Initialize(); // incia protocolo para handshake
while(1)
{
__delay_ms(100);
LED = 1;
__delay_ms(100);
LED = 0;
}
}
qc3.h:
#ifndef QC3_H_ /* Include guard */
#define QC3_H_
/**
Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
//Quick Charge 3 Pin defines
#define DP_HIGH PORTAbits.RA0
#define DM_HIGH PORTAbits.RA1
#define DP_LOW PORTAbits.RA5
#define DM_LOW PORTAbits.RA4
void QC3_Initialize(void);
//void onewireWriteBit(int b);
//unsigned char onewireReadBit();
//unsigned char onewireInit();
//unsigned char onewireReadByte();
//void onewireWriteByte(char data);
//unsigned char onewireCRC(unsigned char* addr, unsigned char len);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif
qc3.c:
#include "qc3.h"
void QC3_Initialize(void) {
__delay_ms(150);
DP_HIGH = 0;
}
Error:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
make -f nbproject/Makefile-default.mk dist/default/production/PIC.production.hex
make[2]: Entering directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
"D:\Program Files\Microchip\xc8\v2.30\bin\xc8-cc.exe" -mcpu=12F1840 -c -mdfp="D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -I"head_and_lib" -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/head_and_lib/qc3.p1 head_and_lib/qc3.c
"D:\Program Files\Microchip\xc8\v2.30\bin\xc8-cc.exe" -mcpu=12F1840 -c -mdfp="D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -I"head_and_lib" -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/source/ISOPOWER.p1 source/ISOPOWER.c
make[2]: *** [build/default/production/head_and_lib/qc3.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
head_and_lib/qc3.c:6:3: error: use of undeclared identifier '_XTAL_FREQ'
__delay_ms(150);
^
D:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8\pic\include\pic.h:101:51: note: expanded from macro '__delay_ms'
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
^
1 error generated.
(908) exit status = 1
nbproject/Makefile-default.mk:123: recipe for target 'build/default/production/head_and_lib/qc3.p1' failed
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/Google Drive/Projetos/Pedais/Fonte para pedais isolada/QUICK CHARGE/PIC'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 913ms)
The compiler complains (use of undeclared identifier '_XTAL_FREQ') but the header in declared AFTER the #define _XTAL_FREQ 500000. Why?
If i remove the delay of the function:
void QC3_Initialize(void) {
__delay_ms(150);
DP_HIGH = 0;
it builds successfully
So. "when" the QC3.c is "called" if it's never declared (even in the ".h" header)?
Why I should declare the ".h" if is the ".c" that includes the ".h"? Shouldn't it be the other way around? Or at least the ".h"
to contain the ".c"?
Seems basic stuff but it's blowing my mind
Thank You
You define _XTAL_FREQ in your C source file containing main() but, since you're calling __delay_ms() in qc3.c (a separate translation unit), that's where that definition needs to exist.
The easiest fix is probably to define it in qc3.h.
you must give _XTAL_FREQ inside the .c file then you may get.

Embedded C in SystemTap - dereferencing pointer to incomplete type

I am following this tutorial: https://blog.lexfo.fr/cve-2017-11176-linux-kernel-exploitation-part1.html
As I try to see what the netlink_sock contains in state, I use this embedded C code:
%{
#include <net/sock.h>
#include <linux/netlink.h>
%}
function dump_netlink_sock:long (arg_sock:long)
%{
struct sock *sk = (void*) STAP_ARG_arg_sock;
struct netlink_sock * nlk = (void*) sk;
_stp_printf("-={ dump_netlink_sock: %p }=-\n", nlk);
_stp_printf("- sk = %p\n", sk);
_stp_printf("- sk->sk_rmem_alloc = %d\n", sk->sk_rmem_alloc);
_stp_printf("- sk->sk_rcvbuf = %d\n", sk->sk_rcvbuf);
_stp_printf("- sk->sk_refcnt = %d\n", sk->sk_refcnt);
_stp_printf("- nlk->state = %x\n", (nlk->state & 0x1));
_stp_printf("-={ dump_netlink_sock: END}=-\n");
%}
probe kernel.function("netlink_attachskb")
{
if (execname() == "exploit")
{
printf("(%d - %d) >>> netlink_attachskb (%s)\n", pid(), tid(), $$parms)
}
dump_netlink_sock($sk);
}
I made sure by myself in the Linux kernel source code - state exists in netlink_sock.
This is my result:
shahar#debian:~/exploitation$ sudo stap -v -g mq_notify.stp
[sudo] password for shahar:
Pass 1: parsed user script and 95 library script(s) using 83352virt/28420res/4880shr/24252data kb, in 0usr/80sys/78real ms.
Pass 2: analyzed script: 699 probe(s), 15 function(s), 5 embed(s), 0 global(s) using 278348virt/102604res/6696shr/97036data kb, in 420usr/730sys/1153real ms.
Pass 3: translated to C into "/tmp/stapFmyHer/stap_cc49251867b5bd20ade8fc721d5f8895_209103_src.c" using 275848virt/102252res/6468shr/97036data kb, in 20usr/10sys/33real ms.
/tmp/stapFmyHer/stap_cc49251867b5bd20ade8fc721d5f8895_209103_src.c: In function ‘function_dump_netlink_sock’:
/tmp/stapFmyHer/stap_cc49251867b5bd20ade8fc721d5f8895_209103_src.c:2517:41: error: dereferencing pointer to incomplete type
_stp_printf("- nlk->state = %x\n", (nlk->state & 0x1));
^
make[3]: *** [/tmp/stapFmyHer/stap_cc49251867b5bd20ade8fc721d5f8895_209103_src.o] Error 1
make[2]: *** [_module_/tmp/stapFmyHer] Error 2
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
WARNING: kbuild exited with status: 2
Pass 4: compiled C into "stap_cc49251867b5bd20ade8fc721d5f8895_209103.ko" in 130usr/380sys/740real ms.
Pass 4: compilation failed. [man error::pass4]
Tip: /usr/share/doc/systemtap/README.Debian should help you get started.
In addition, I tried to create my own struct (basically copied netlink_sock from Linux source, but I could not get it compiled - I am not sure where to place my struct in the .stp file.

mingw64 pjsip sizeof(fd_set) always double sizeof(pj_fd_set_t) causing assertion in sock_select.c

I've compiled pjsip into my program that I'm writing in an msys2/mingw environment (64-bit). It compiles fine. However, when I run it in my program I'm getting an assertion
// Line 49 of ../src/pj/sock_select.c
sizeof(pj_fd_set_t)-sizeof(pj_sock_t)>=sizeof(fd_set)
Every time I run the program.
When I do some digging people talk about increasing PJ_IOQUEUE_MAX_HANDLES. So I did, and I put a printf in the function before the asserts to see what the sizes are:
// My PJ_FD_ZERO variant
PJ_DEF(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp)
{
printf( "PJ_IOQUEUE_MAX_HANDLES: %d, pj_fd_set_t: %I64d, pj_sock_t: %I64d, fd_set: %I64d\n", PJ_IOQUEUE_MAX_HANDLES, sizeof(pj_fd_set_t), sizeof(pj_sock_t), sizeof(fd_set) );
PJ_CHECK_STACK();
pj_assert(sizeof(pj_fd_set_t)-sizeof(pj_sock_t) >= sizeof(fd_set));
FD_ZERO(PART_FDSET(fdsetp));
PART_COUNT(fdsetp) = 0;
}
The program will output something like this:
10:27:43.477 os_core_win32.c !pjlib 2.9 for win32 initialized
10:27:43.507 sip_endpoint.c .Creating endpoint instance...
PJ_IOQUEUE_MAX_HANDLES: 16384, pj_fd_set_t: 65552, pj_sock_t: 4, fd_set: 131080
However, when I tweak PJ_IOQUEUE_MAX_HANDLES the size of pj_fd_set_t increases as it should but! the sizeof(fd_set) also becomes slight less than DOUBLE whatever sizeof(pj_fd_set_t) is! The winsock guide says that I cannot set the size of fd_set so I am very confused how the size is getting set! I don't see anywhere in the pjsip code that this is being set.
So adjusting PJ_IOQUEUE_MAX_HANDLES is quite the losing battle.
How can I fix this so my code will stop asserting?
Some references
Bash script that I ran to configure pjsip
#!/bin/bash
JOPT=1
DEBUG=false
BUILD_ALL=true
CLEAN_BEFORE_BUILD=false
TOUCH_COMMAND="touch configure.ac aclocal.m4 configure Makefile.am Makefile.in"
while getopts ":pdj:o:c" opt; do
case $opt in
j)
JOPT="$OPTARG"
;;
c)
echo "Clean before build is set."
CLEAN_BEFORE_BUILD=true;
;;
d)
DEBUG=true
;;
o)
IFS=', ' read -r -a BUILD_OPTS <<< "${OPTARG}"
BUILD_ALL=false
for option in "${BUILD_OPTS[#]}" ; do
# Set individual
case $option in
pjsip)
BUILD_PJSIP=true;
;;
*)
echo "Unknown build option ${option}"
exit
esac
done
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
exit 1
;;
esac
done
# Make the out
mkdir out
OUT_PREFIX="$( pwd )/out"
export PKG_CONFIG_PATH="${OUT_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
if [ "$DEBUG" = true ] ; then
MAKEFLAGS="-g -O0"
else
MAKEFLAGS="-O2"
fi
# Main directory
LIB_DIRECTORY="$(pwd)/lib"
# Descend
cd "${LIB_DIRECTORY}"
pwd
# pjsip
cd "${LIB_DIRECTORY}/pjsip"
if [ "${BUILD_ALL}" = true ] || [ "${BUILD_PJSIP}" = true ] ; then
eval $TOUCH_COMMAND
./configure CFLAGS="${MAKEFLAGS} -I${OUT_PREFIX}/include" CXXFLAGS="${MAKEFLAGS}" LDFLAGS="-L${OUT_PREFIX}/lib" \
--prefix="${OUT_PREFIX}" \
--disable-openh264 \
--disable-v4l2 \
--disable-ffmpeg \
--enable-libsamplerate \
--disable-video \
--enable-shared \
--disable-static \
--disable-libyuv \
--with-external-speex \
--with-gnutls \
|| exit
if [ "${CLEAN_BEFORE_BUILD}" = true ] ; then
make clean
fi
# Without this it breaks on msys2
make -j $JOPT dep || exit
# Make the actual
make -j $JOPT || exit
# Note, had issue with writing to //c/.../pkgconfig/libproject.pc
make install || exit
fi
The assert screenshot
--Edit--
Funny enough when I run this program the sizeof( fd_set ) is 520.
#include <winsock.h>
#include <iostream>
int main( int argc, char *argv[] )
{
std::cout <<
"sizeof( fd_set )=" << sizeof( fd_set ) << "\n"
"FD_SETSIZE=" << FD_SETSIZE << std::endl;
return( EXIT_SUCCESS );
}
Result:
sizeof( fd_set )=520
FD_SETSIZE=64
I'm that guy again answering my own question.
I think what was going on is that pjsip wasn't detecting that I was using windows with mingw despite it being detected on configure.
checking build system type... x86_64-w64-mingw32
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
I found this little nugget in the types.h
/** Socket handle. */
#if defined(PJ_WIN64) && PJ_WIN64!=0
typedef pj_int64_t pj_sock_t;
#else
typedef long pj_sock_t;
#endif
I think realized that pj_fd_set_t (which is comprised of pj_sock_t) would be smaller always than fd_set (which is comprised of fd) if the sizes are off. That would explain the proportional phenomenon. This is also because PJSIP defines FD_SETSIZE on Windows when detected.
So I just ran ./configure as I did above and then manually modified:
build.mak
build/os-auto.mak
Replacing PJ_AUTOCONF=1 with PJ_WIN32=1.
Then I manually modified the Makefile explicitly including the correct file.
include build/os-win32.mak
And then I compiled using make dep && make && make install
Finally, when I compiled it into my program it complained about implementing unicode string functions, so I looked at the file threw the error (pj/compat/string.h). I found the line #if defined(_MSC_VER) and added some more definitions as below to support MINGW macros.
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# define snwprintf _snwprintf
# define wcsicmp _wcsicmp
# define wcsnicmp _wcsnicmp
#else
# define stricmp strcasecmp
# define strnicmp strncasecmp
# if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
# error "Implement Unicode string functions"
# endif
#endif
Then it worked!

Error on compiling c file on MPLAB X ide

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.

Resources