undeclared identifier 'byte'. compile C code - c

I'm trying to compile library from .c file in Xcode. (It doesn't give me any errors in Visual Studio on Windows) But Xcode gives:
Use of undeclared identifier 'byte'
in the next line:
buf[2] = (byte)(addr & 0xff);

In the .c file i have declared byte with the next code:
typedef uint8_t byte
uint8_t is similar to byte, so it compiled

Related

Compatibility between IAR C/C++ Compiler and GCC

I have a code-block, which is written in C for IAR C/C++ Compiler.
__no_init uint8_t u8ramPhysStart_startUp # 0x20000000;
__no_init uint8_t u8ramPhysEnd_startUp # 0x2002FFFF;
__no_init uint8_t u8ramTestStart_startUp # 0x20004008;
__no_init uint8_t u8ramTestEnd_startUp # 0x20008008;
#define START_ASM (&u8ramPhysStart_startUp)
#define RAMSTART_STRTUP ((uint32_t)START_ASM)
My goal is converting it or rather making it GCC compatible. For this, I rewrite above code like:
unsigned char u8ramPhysStart_startUp __asm("# 0x20000000");
unsigned char u8ramPhysEnd_startUp __asm("# 0x2002FFFF");
unsigned char u8ramTestStart_startUp __asm("# 0x20004008");
unsigned char u8ramTestEnd_startUp __asm("# 0x20008008");
But after compilation I get following error:
C:\Users\Pc\AppData\Local\Temp\ccyuCWQT.s: Assembler messages:
C:\Users\Pc\AppData\Local\Temp\ccyuCWQT.s:971: Error: expected symbol name
C:\Users\Pc\AppData\Local\Temp\ccyuCWQT.s:972: Error: expected symbol name
Do someone knows, what it means?
I believe the gcc code should be something like
uint8_t __attribute__ ((section(".my_section"))) u8ramPhysStart_startUp;
where .my_section is something you have added to the linker script.
That being said, the only way which you can make allocation at absolute addresses portable, is to stick to pure ISO C:
#define u8ramPhysStart_startUp (*(volatile uint8_t*)0x20000000u)
or in case you want a pointer to an address:
#define u8ramPhysStart_startUp ((volatile uint8_t*)0x20000000u)
The disadvantage of this is that it doesn't actually allocate any memory, but relies on a linker script to handle that part. That's preferable in most cases.
Another disadvantage is that you won't be able to view these "variable" names in a debugger, since they are actually not variables at all. And that's the main reason why some tool chains come up with things like the non-standard # syntax.

c library creation for ATMEL328

I am trying to create a library in C for use in a ATMEL 328pu. I have made the source and header files in C but come unstuck when I try to compile the library. I think I need another AVR library containing the types:
TWDR
TWCR
Which are the i2c registers in the ATMEGA328. A shortened version of the error message can be seen below followed by a portion of the .cpp file where the error message refers too.
Error message:
Build: Debug in my_i2c (compiler: GNU GCC Compiler)
Code_blocks/my_i2c/my_i2c/my_i2c.cpp|39|error: use of undeclared identifier 'TWCR'|
Build failed: 19 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Extract from.cpp file:
#include "my_i2c.h"
/////////////////////WRITE BIT////////////////////
void my_i2c :: i2cWriteBit (uint8_t i2cAdd, uint8_t i2cReg, uint8_t i2cBit, bool i2cBool) {
uint8_t writeBuff;
writeBuff = i2cRead(i2cAdd, i2cReg); //read uint8_t
i2cBool == true ? writeBuff |= 1 << i2cBit : writeBuff &= ~(1 << i2cBit);
i2cWrite (i2cAdd, i2cReg, writeBuff);
}
/////////////////////WRITE uint8_t////////////////////
void my_i2c :: i2cWrite (uint8_t i2cAdd, uint8_t i2cReg, uint8_t i2cData) {
/////START CONDITION////
TWCR = 0b10100100; //(TWINT)(TWSTA)(TWEN) - Set START condition
while (!(TWCR & 0b10000000)) { //Wait for TWI to set TWINT
}
Do I need to define the what TWCR and TWDR are for the compiler to understand the functions? and how do I do this, is it like I was thinking by including another library?
You can't refer to an undeclared identifier, that makes it impossible for the compiler to figure out what you mean.
You should probably add
#include <avr/io.h>
to your library's source code.

How to link the library files for a C program in makefile in UNIX?

I have written a decryption function using openssl which I tested in a standalone program and it worked fine. But this function is a part of a huge project so it has to be included in that program.
To execute my standalone program I used the following commands which worked fine:
cc -c aaa.c -I/usr/local/ssl/include
gcc -o aaa aaa.o -I/usr/local/ssl/include -L/usr/local/ssl/lib -lcrypto -lm
./aaa
I have made a makefile for my main program inside which this function will be called.
Both the programs are working fine individually but when I inserted the definition on the function in my program, it gave me errors for those variables which were in one of the header file of openssl (i.e. des.h).
I have made use of a few variables of type DES_cblock:
typedef unsigned char DES_cblock[8];
There is another structure with the following definition:
typedef struct DES_ks
{
union
{
DES_cblock cblock;
DES_LONG deslong[2];
}ks[16];
} DES_key_schedule;
I have made use of this structure in my program like this
DES_key_schedule keysched1,keysched2,keysched3;
But it is not recognizing these variables. And since there was no such error when I was executing my standalone program it means that I am not able to link the library files properly in the main program. How do I make this work.
These are the errors that I am getting:
Syntax error at line 1399, column 16,file/export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1399, column 16 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
DES_cblock hex_key1,hex_key2,hex_key3,hex_ivec,iv;
...............1
PCC-S-02201, Encountered the symbol "hex_key1" when expecting one of the followi
ng:
; , = : ( [ * ? | & < > + - / % . ^ *= /= %= += -= <<= >>=
&&= ||= ^= | & == != <= >= << >> ++ -- ->
The symbol ";" was substituted for "hex_key1" to continue.
Syntax error at line 1402, column 22, file /export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1402, column 22 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
DES_key_schedule keysched1,keysched2,keysched3;
.....................1
PCC-S-02201, Encountered the symbol "keysched1" when expecting one of the follow
ing:
; , = : ( [ * ? | & < > + - / % . ^ *= /= %= += -= <<= >>=
&&= ||= ^= | & == != <= >= << >> ++ -- ->
The symbol ";" was substituted for "keysched1" to continue.
Syntax error at line 1436, column 38, file /export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1436, column 38 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
if (DES_set_key_checked((C_Block *)hex_key1, &keysched1))
Now I just need to link the library files properly in my program to make the whole program running. The header file as mention before is des.h which is a part of openssl.
I tried including the crypto library also by -lcrypto
Previously this des.h was not getting included properly but now have I included the des.h successfully without error.
Someone also suggested that merely including the header file is not enough and its implementation file also needs to be linked, so I now I want to know how to include and link what?
How to find out the name of the link which needs to be linked.
Typically, you define -l options to the linker using LDLIBS, and -L flags using LDFLAGS. Edit the Makefile and add the appropriate options.
CPPFLAGS += -I/usr/local/ssl/include
LDFLAGS += -L/usr/local/ssl/lib
LDLIBS += -lcrypto -lm
These are compiler errors, you haven't got to the linking stage yet.
I would guess that, when compiling tgl_frbsenddata.ec, the compiler doesn't know what a DES_cblock is or a DES_key_schedule. At the point where the compiler hits the lines with the errors in, I suspect des.h has not yet been included whatever you may believe about whether you have or not.
Your compiler probably includes an option to do preprocessing only (in gcc and clang, it is -E). I suggest you run it with that option on your source file to see if the typedefs appear.

porting C compilation from MinGW to VisualStudio(nmake)

My current job at the university is to port a C program from MinGW (windows) to Visual Studio (nmake).
I have got a valid "makefile.vc" file for a very similar C program.
My approach was to adopt the Makefile (i.e. "makefile.vc") to the program I need to port.
All but four C files seem to compile fine. Those four files have various errors for example, syntax errors and "unknown size".
Should I continue with my approach to change the Makefile or use CMAKE instead of nmake?
Is there a tutorial or any other pointer on porting a C program from MinGW/gcc to nmake?
typedef struct {
A_TypeConverter *converter;
char *domain;
} enumeratorConverterEntry;
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
error:
f.c(186) : error C2133: 'enumeratorConverterEntries' : unknown size
typedef struct AsmInstructionInfo {
int flags;
CONST char **argTypes; /* line 7 */
int minArgs;
int maxArgs;
int cArgs;
} AsmInstructionInfo;
error:
fAssemble.c(7) : error C2061: syntax error : identifier 'CONST'
..
/* file fStack.c: */
#ifdef CHECK_ACTIVATION_COUNTS
/* code */
#endif
/* more code */
void fShowStack(l_Interp *interp) { /* line 94 */
l_CallFrame *framePtr;
/* more code */
error:
fStack.c(94) : error C2143: syntax error : missing ')' before '*'
fStack.c(94) : error C2143: syntax error : missing '{' before '*'
fStack.c(94) : error C2059: syntax error : ')'
fStack.c(94) : error C2054: expected '(' to follow 'interp'
static enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
That looks like a valid incomplete, forward declaration of an array, which would be valid syntax, except I think for the static qualifier. I don't have a copy of the 'C' standard in front of me, but reading between the lines on the results of Googling "forward declaration of static array" seems to indicate that an incomplete definition of a static array results in undefined behavior, so Microsoft and GNU are legitimately entitled to do whatever they want with it. GNU accepts it, and Microsoft rejects it. As Mark Wilkins points out you should be make the Microsoft compiler happy by replacing it with:
extern enumeratorConverterEntry enumeratorConverterEntries[]; /* line 186 */
In general it's worth noting that the Microsoft compiler only supports the C89 standard, while the GNU compiler supports portions of the C99 standard, and several of their own extensions, depending on the arguments to the compiler.
The errors in fAssemble.c and fStack.c look like one or more preprocessor files are missing or incomplete. You should search your source to find out where CONST and l_Interp are defined, and then figure out why they are not being picked up in the files where the errors are occurring.
I just now tried out that array declaration with MinGW, and it does compile. To make it link, though, it needs the array to be defined elsewhere. The result is that it appears to be the same as the extern storage class:
extern enumeratorConverterEntry enumeratorConverterEntries[];
I'm not sure if there are other subtleties associated with the original declaration using a static storage class for the global.

Linking a library in g++ doesn't work

I am trying to compile a .cpp-file which uses a matrix-library. The library-files libnewmat.a and libnewmat.so are in the path /usr/lib64 . The include-files are in path /usr/include/newmat , so I tried (several ways) to compile i.e. with:
g++ -I/usr/include -L/usr/lib64 -lnewmat new.cpp -o new3
but the compiler doesn't find the library. The content of the .cpp is:
#include <iostream>
#include <newmat/newmat.h>
#include <newmat/newmatio.h>
using namespace std;
int main()
{
Matrix A(2,2);
Real b[] = {1,2,3,4};
A << b;
cout << A << endl;
return 0;
}
The compiler says:
test.cpp: In function ‘int main()’:
test.cpp:9: error: ‘Matrix’ was not declared in this scope
test.cpp:9: error: expected ‘;’ before ‘A’
test.cpp:10: error: ‘Real’ was not declared in this scope
test.cpp:10: error: expected ‘;’ before ‘b’
test.cpp:11: error: ‘A’ was not declared in this scope
test.cpp:11: error: ‘b’ was not declared in
this scope
Could You provide me with the correct c++ code, or the correct command line instruction?
Thanks, Kepler
If you recently installed this library yourself you probably need to run sudo ldconfig to load the so into the linker cache.
EDIT: As Kevin said not a linking error that you're getting.
Perhaps it's a name space issue?
using namespace NEWMAT;
according to this: http://www.robertnz.net/nm10.htm#namesp
This isn't a library problem - it's a compiler problem - it can't find any definition for Matrix (probably in your include files, but we can't determine that with the information given)
[edit]
Ascertain if your classes in the include files are being referenced correctly
[/edit]

Resources