Does anybody know what is wrong with this piece of code? i can’t see to find the issue among the comparable questions.
The code is written in C, and i keep getting this error. I do add -D SET_MIN_TEMP=5 -D Set_MAX_TEMP=30
to the gcc compile line to make sure the ifndefs should be false…
#ifndef CONFIG_H
#define CONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#ifndef RUN_AVG_LENGTH
#define RUN_AVG_LENGTH 5
#endif
#ifndef SET_MIN_TEMP
printf("please set SET_MIN_TEMP n");
#endif
#ifndef SET_MAX_TEMP
printf("please set SET_MAX_TEMP n");
#endif
typedef uint16_t sensor_id_t;
typedef uint16_t room_id_t;
typedef double sensor_value_t;
typedef time_t sensor_ts_t; // UTC timestamp as returned by time() - notice that the size of time_t is different on 32/64 bit machine
typedef struct {
sensor_id_t id;
sensor_value_t value;
sensor_ts_t ts;
} sensor_data_t;
typedef struct {
sensor_id_t sensor_id;
room_id_t room_id;
double running_avg[5];
sensor_ts_t timestamp;
} sensor_node_t;
#endif // CONFIG_H
Barmar
718k53 gold badges481 silver badges598 bronze badges
asked Apr 13, 2016 at 18:30
6
You can not use a function call (printf
) outside a function. You should take a look at #error
if you want to report errors at compilation…
See here
answered Apr 13, 2016 at 18:35
mame98mame98
1,23115 silver badges26 bronze badges
5
I am getting an error on a specific line that mimics the usage in another file.
PyObject *pyCharGetHeight(PyChar *self, void *closure) {
CHAR_DATA *ch = PyChar_AsChar((PyObject *)self);
PyObject *height = NULL;
if(ch != NULL) height = Py_BuildValue("s", charGetHeight(ch));
return height;
}
PyChar_addGetSetter("height", pyCharGetHeight, NULL, "Returns character's height");
is returning the following error, PyChar_addGetSetter… line
error: expected declaration specifiers or â…â before string constant
I am using the following includes:
#include <Python.h>
#include "../scripts/pychar.h"
And pychar.h does define PyChar_addGetSetter() as prototyped here:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc);
The function is written in ../scripts/pychar.c as follows:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc) {
// make sure our list of get/setters is created
if(pychar_getsetters == NULL) pychar_getsetters = newList();
// make the GetSetter def
PyGetSetDef *def = calloc(1, sizeof(PyGetSetDef));
def->name = strdup(name);
def->get = (getter)g;
def->set = (setter)s;
def->doc = (doc ? strdup(doc) : NULL);
def->closure = NULL;
listPut(pychar_getsetters, def);
}
It seems like a structure or type is not being recognized, I am guessing my function.
I had the same problem. My error messages were:
TarHeader.h:15:24: error: expected declaration specifiers or '...' before numeric constant TarHeader.c:69:61: error: expected declaration specifiers or '...' before string constant
And the specific lines of code were:
* Line 15 in TarHeader.h:
#define TAR_BLOCK_SIZE 512
* Line 69 (v1) in TarHeader.c:
static_assert(TAR_BLOCK_SIZE == sizeof(tar_posix_header_t), "Incorrect header definition");
When I tried to change it I changed the includes in «TarHeader.c» (removed include of «TarHeader.h»)
The line seems then like this (Line 69 (v2) in TarHeader.c)
static_assert(512== sizeof(tar_posix_header_t), "Incorrect header definition");
And the error codes changed:
TarHeader.c:69:15: error: expected declaration specifiers or '...' before numeric constant TarHeader.c:69:50: error: expected declaration specifiers or '...' before string constant
When I removed line 65 of «TarHeader.c» no error was reported even with the previously used include.
The static assert was copied from another project (also in C) ane there was no problem. But it was a different compiler.
Solution:
Search for the use of these defines and see what use causes this problem.
Forum rules
Before you post please read how to get help. Topics in this forum are automatically closed 6 months after creation.
-
hhbuur
- Level 1
- Posts: 12
- Joined: Thu Feb 15, 2018 1:17 pm
[SOLVED]Make error
Can I get some help with understand these error messages. I am trying to make a hello world.
#include<linux/init.h>
#include<linux/module.h>MODUL_LICENSE(«GPL»);
static int hello_init(void)
{
printk(KERN_ALERT «Hello world»);
retur 0;
}static void hello_exit(void)
{
printk(KERN_Alert «Goodby»);
}module_init(hello_init);
module_exit(hello_exit);obj-m +=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
hhb # make
make -C /lib/modules/4.13.0-39-generic/build M=/home/hans/hhb modules
make[1]: Entering directory ‘/usr/src/linux-headers-4.13.0-39-generic’
CC [M] /home/hans/hhb/hello.o
/home/hans/hhb/hello.c:4:15: error: expected declaration specifiers or ‘…’ before string constant
MODUL_LICENSE(«GPL»);
^
/home/hans/hhb/hello.c: In function ‘hello_init’:
/home/hans/hhb/hello.c:9:1: error: ‘retur’ undeclared (first use in this function)
retur 0;
^
/home/hans/hhb/hello.c:9:1: note: each undeclared identifier is reported only once for each function it appears in
/home/hans/hhb/hello.c:9:7: error: expected ‘;’ before numeric constant
retur 0;
^
/home/hans/hhb/hello.c:10:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
/home/hans/hhb/hello.c: In function ‘hello_exit’:
/home/hans/hhb/hello.c:14:8: error: ‘KERN_Alert’ undeclared (first use in this function)
printk(KERN_Alert «Goodby»);
^
/home/hans/hhb/hello.c:14:19: error: expected ‘)’ before string constant
printk(KERN_Alert «Goodby»);
^
scripts/Makefile.build:323: recipe for target ‘/home/hans/hhb/hello.o’ failed
make[2]: *** [/home/hans/hhb/hello.o] Error 1
Makefile:1550: recipe for target ‘_module_/home/hans/hhb’ failed
make[1]: *** [_module_/home/hans/hhb] Error 2
make[1]: Leaving directory ‘/usr/src/linux-headers-4.13.0-39-generic’
Makefile:4: recipe for target ‘all’ failed
make: *** [all] Error 2
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Linux Mint XFce 19.3
Lenovo ThinkPad W530 /2010
-
rene
- Level 20
- Posts: 11402
- Joined: Sun Mar 27, 2016 6:58 pm
Re: Make error
Post
by rene » Sat Jul 28, 2018 4:49 pm
You have 3 obvious typo’s, all of which are pointed out by the error messages. Modulo module signing, the only thing that’s otherwise wrong is that you should end your printk strings with «n» so as to flush them to the kernel message buffer.
-
hhbuur
- Level 1
- Posts: 12
- Joined: Thu Feb 15, 2018 1:17 pm
Re: Make error
Post
by hhbuur » Sat Aug 11, 2018 1:12 pm
thanks fore your reply, that help.
can you help me white the next step, i am getting a messed when compelling and the compelling only make two file, «Module.symvers and modules.order» and both are empty.
Code: Select all
MJ # make
make -C /lib/modules/4.13.0-39-generic/build M=/home/MJ modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-39-generic'
CC [M] /home/MJ/hello.o
/home/MJ/hello.c:1:2: error: invalid preprocessing directive #inClude
#inClude<linux/init.h>
^
/home/MJ/hello.c:2:2: error: invalid preprocessing directive #inClude
#inClude<linux/module.h>
^
/home/MJ/hello.c:4:16: error: expected declaration specifiers or ‘...’ before string constant
MODULE_LICENSE("GPL");
^
/home/MJ/hello.c:6:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
statiC int hello_init(void)
^
/home/MJ/hello.c:12:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
statiC void hello_exit(void)
^
/home/MJ/hello.c:17:1: warning: data definition has no type or storage class
module_init(hello_init);
^
/home/MJ/hello.c:17:1: error: type defaults to ‘int’ in declaration of ‘module_init’ [-Werror=implicit-int]
/home/MJ/hello.c:17:1: warning: parameter names (without types) in function declaration
/home/MJ/hello.c:18:1: warning: data definition has no type or storage class
module_exit(hello_exit);
^
/home/MJ/hello.c:18:1: error: type defaults to ‘int’ in declaration of ‘module_exit’ [-Werror=implicit-int]
/home/MJ/hello.c:18:1: warning: parameter names (without types) in function declaration
cc1: some warnings being treated as errors
scripts/Makefile.build:323: recipe for target '/home/MJ/hello.o' failed
make[2]: *** [/home/MJ/hello.o] Error 1
Makefile:1550: recipe for target '_module_/home/MJ' failed
make[1]: *** [_module_/home/MJ] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-39-generic'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
hans MJ # vi Makefile
the Makefile
Code: Select all
obj-m +=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Linux Mint XFce 19.3
Lenovo ThinkPad W530 /2010
-
rene
- Level 20
- Posts: 11402
- Joined: Sun Mar 27, 2016 6:58 pm
Re: Make error
Post
by rene » Sat Aug 11, 2018 1:47 pm
You now have one obvious typo, again as pointed out by the error message: there’s no directive called «inClude». Let me just post the corrected hello.c.
Code: Select all
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int __init hello_init(void)
{
printk(KERN_ALERT "Hello worldn");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Goodbyen");
}
module_init(hello_init);
module_exit(hello_exit);
Note that I added __init and __exit to to hello_init resp. hello_exit. Do not matter here but should be present generally: when the module’s built-in to the kernel __init causes a function to be placed in an after initialization discardable section of the kernel and __exit code is discarded outright.
Code: Select all
rene@hp8k ~/hello $ make
make -C /lib/modules/4.15.0-30-generic/build M=/home/rene/hello modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-30-generic'
Makefile:976: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
CC [M] /home/rene/hello/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/rene/hello/hello.mod.o
LD [M] /home/rene/hello/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-30-generic'
rene@hp8k ~/hello $ sudo insmod ./hello.ko && sudo rmmod hello
[sudo] password for rene:
rene@hp8k ~/hello $ dmesg -t | tail -2
Hello world
Goodbye
Before those two lines dmesg will you telll that insmoding an unsigned module will taint your kernel. Module signing will undoubtedly, hopefully, be explained in the next section of whichever source you are consulting; if not, for now just ignore it.
[EDIT] For some odd reason, the module_init() and module_exit() got stripped from above paste of hello.c; added back again.
-
hhbuur
- Level 1
- Posts: 12
- Joined: Thu Feb 15, 2018 1:17 pm
Re: Make error
Post
by hhbuur » Sat Aug 18, 2018 8:04 am
I have come a little further but there is something I do not understand, in the manual there are printet three lines as a result while I only get one, or say otherwise it seems I do not get anything Array
the code
Code: Select all
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
int paramArray[3];
module_param_array(paramArray, int,NULL, S_IWUSR | S_IRUSR);
static int __init array_init(void)
{
printk("Into the parameter Array demon");
printk("Array elements are :%dt%dt%d",paramArray[0],paramArray[1],paramArray[2]);
return 0;
}
static void array_exit(void)
{
printk(KERN_ALERT "Exiting the array parameter demon");
}
module_init(array_init);
module_exit(array_exit);
make
Code: Select all
make
make -C /lib/modules/4.13.0-39-generic/build M=/home/MJ modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-39-generic'
CC [M] /home/MJ/parameterArray.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/MJ/parameterArray.mod.o
LD [M] /home/MJ/parameterArray.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-39-generic'
the result
Code: Select all
sudo insmod parameterArray.ko paramArray=1,2,3
/home/MJ $ dmesg | tail -5
[ 58.076836] thinkpad_acpi: EC reports that Thermal Table has changed
[ 952.370581] INTO the parameter Array demo
[ 952.370583] Array elements are :1 2 3
[ 1555.760650] Exiting the array parameter demo
[ 1702.026904] INTO the parameter Array demo
Linux Mint XFce 19.3
Lenovo ThinkPad W530 /2010
-
rene
- Level 20
- Posts: 11402
- Joined: Sun Mar 27, 2016 6:58 pm
Re: Make error
Post
by rene » Sat Aug 18, 2018 8:34 am
hhbuur wrote: ↑
Sat Aug 18, 2018 8:04 am
[ … ] in the manual there are printet three lines as a result while I only get one
This is again the issue of you not flushing messages to the kernel message buffer; of you not ending the «Array elements are» printk() with a newline.
Two other remarks: while printk() has a default log level (KERN_WARNING normally) not explicitly specifying one as you do in but one instance is frowned upon. Also, if you mark your module_init() function __init consistency kindly requests you mark your module_exit() function __exit…
One additional remark… you may have in the form of this forum picked one of the worst possible places to go learn Linux kernel programming. It seems the kernelnewbies project is still alive: https://forum.kernelnewbies.org/ and/or https://kernelnewbies.org/ML. That would no doubt be a far better choice.
-
hhbuur
- Level 1
- Posts: 12
- Joined: Thu Feb 15, 2018 1:17 pm
Re: Make error
Post
by hhbuur » Thu Aug 23, 2018 8:42 am
ok i consider the problem sloved
Linux Mint XFce 19.3
Lenovo ThinkPad W530 /2010
0
0
Добрый день!
При компиляции libpcap возникла непонятная ошибка:
gcc -nodefaultlibs -nostdlib -fPIC -static -I/home/xvilka/build/cross/sys-root/usr/include -O2
-fPIC -nodefaultlibs -nostdlib -fPIC -static -I/home/xvilka/build/cross/sys-root/usr/include -I.
-DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -c ./pcap-usb-linux.c
In file included from ./pcap-usb-linux.c:57:
/home/xvilka/build/cross/sys-root/usr/include/string.h:431: error: expected declaration specifiers or '...' before '(' token
/home/xvilka/build/cross/sys-root/usr/include/string.h:431: error: expected declaration specifiers or '...' before '(' token
/home/xvilka/build/cross/sys-root/usr/include/string.h:431: error: expected declaration specifiers or '...' before '(' token
/home/xvilka/build/cross/sys-root/usr/include/string.h:431: error: expected ')' before ',' token
make[1]: *** [pcap-usb-linux.o] Error 1
В чем может быть проблема? (такую ошибку в первый раз встречаю)
Некоторые флаги компилятора повторяются, хотя при .configure были заданы один раз, но уверен это не играет здесь роли.
Помогите с решением, спасибо!
На чтение 2 мин Обновлено 18.01.2023
Arch Linux
You are not logged in.
#1 2012-07-31 08:48:08
[SOLVED] Problem with GCC
Hi guys!
I have a problem with gcc.
I’m trying to learn how to program sockets using C.
So i followed a tuotrial and i wrote up a little client server, but when i try to compile it i can’t do it.
These is the client:
When i try to compile it i got many errors. I don’t know why, i followed a tutorial so the code should be corrected.
These is the output:
Last edited by Ananke (2012-07-31 13:36:37)
#2 2012-07-31 08:56:54
Re: [SOLVED] Problem with GCC
Is this your actual code?
You forgot the semicolon after «int CSocket», then.
This was the hint in the error messages:
To know or not to know .
. the questions remain forever.
#3 2012-07-31 11:18:04
Re: [SOLVED] Problem with GCC
Yup, also the first error tells you what is missing. When you get error output while compiling always focus on the first error message. Often one error early in the code can lead to lots of other problems, so the first error message tells you what to fix.
Additionally, while there are many different coding «styles» I don’t know of any that don’t use indentation to highlight the structure of the code. That would make this code much easier to read.
«UNIX is simple and coherent. » — Dennis Ritchie, «GNU’s Not UNIX» — Richard Stallman
Online
#4 2012-07-31 11:45:36
Re: [SOLVED] Problem with GCC
Thank you for help guys.
I’m not really good with english language and i don’t understand what «semicolon after int Csocket» means. May you explain me how i should modify the code?
I use Geany as editor, so i can see the higlight of sintax with colours. If you want here is the code with highlighting:
http://pastebin.com/fdci4mPk
Last edited by Ananke (2012-07-31 13:12:36)
Источник
Ожидаемые спецификаторы объявления или ‘…’ перед строковой константой
я осознаю Expected declaration specifiers or '...' before string constant
ошибка в mach_override.c in проект scplugin во второй строке кода ниже.
asm(
".text;"
".align 2, 0x90;"
".globl _atomic_mov64;"
"_atomic_mov64:;"
" pushl %ebp;"
" movl %esp, %ebp;"
" pushl %esi;"
" pushl %ebx;"
" pushl %ecx;"
" pushl %eax;"
" pushl %edx;"
// atomic push of value to an address
// we use cmpxchg8b, which compares content of an address with
// edx:eax. If they are equal, it atomically puts 64bit value
// ecx:ebx in address.
// We thus put contents of address in edx:eax to force ecx:ebx
// in address
" mov 8(%ebp), %esi;" // esi contains target address
" mov 12(%ebp), %ebx;"
" mov 16(%ebp), %ecx;" // ecx:ebx now contains value to put in target address
" mov (%esi), %eax;"
" mov 4(%esi), %edx;" // edx:eax now contains value currently contained in target address
" lock; cmpxchg8b (%esi);" // atomic move.
// restore registers
" popl %edx;"
" popl %eax;"
" popl %ecx;"
" popl %ebx;"
" popl %esi;"
" popl %ebp;"
" ret"
);
Allow asm, inline typeof
Флаг установлен в моих настройках сборки. кто-нибудь может мне помочь?
Сделайте следующее изменение (во флагах):
C language dialect = Compiler Default
Создан 02 янв.
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
objective-c
xcode
gcc
inline-assembly
or задайте свой вопрос.
remzona 1 / 1 / 0 Регистрация: 03.07.2016 Сообщений: 58 |
||||||||
1 |
||||||||
Модуль ядра, некорректная работа15.07.2020, 08:49. Показов 1627. Ответов 8 Метки нет (Все метки)
Здравствуйте!, изучаю тему написания модулей ядра. Начал с Hello, world.
Естетсвенно после insmod я ожидаю Starting… в syslog и Exit… после rmmod, но вывод получается наоборот:
В чём моя ошибка?
__________________
0 |
550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
|
17.07.2020, 21:46 |
2 |
Какое ядро? Как компилишь?
0 |
308 / 168 / 46 Регистрация: 18.10.2017 Сообщений: 1,585 |
|
18.07.2020, 17:20 |
3 |
drfaust, сам пример очень устаревший. И что, это всё содержимое?
0 |
1 / 1 / 0 Регистрация: 03.07.2016 Сообщений: 58 |
|
28.07.2020, 08:45 [ТС] |
4 |
Прошу прощения за долгое отсутствие, проблема решилась сама собой. Мне пояснили, что всё дело в буферизации вывода, это можно исправить. Правда пока не рассказали как
0 |
drfaust 550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
||||
28.07.2020, 19:53 |
5 |
|||
Сообщение было отмечено remzona как решение РешениеПопробуй
По идее, перевод строки может сбросить буфер
1 |
Dexel 46 / 13 / 3 Регистрация: 29.09.2013 Сообщений: 289 |
||||
24.09.2020, 19:59 |
6 |
|||
Код # dmesg -c [13284.673059] Starting module... [13604.719906] Exit module... Добавлено через 13 минут
0 |
drfaust 550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
||||
24.09.2020, 20:03 |
7 |
|||
Dexel, Хм…
0 |
Dexel 46 / 13 / 3 Регистрация: 29.09.2013 Сообщений: 289 |
||||||||
24.09.2020, 21:01 |
8 |
|||||||
Даже на printk ругается… оригинально. Та может на арче ядро другое, не знаю. У ТС тоже нормально компилит.
Добавлено через 47 минут
Код # insmod modulehelloworld.ko # dmesg -c [18251.333649] Starting module... # rmmod modulehelloworld # dmesg -c [18259.893036] Exit module...
1 |
550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
|
26.09.2020, 22:05 |
9 |
Уже пытался объяснить… Добавлено через 2 минуты
Даже на printk ругается… оригинально. Ну если другие модули дрова компилятся из сырцов — то всё в норм, но я make не писал — тупо gcc зарядил…
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
26.09.2020, 22:05 |
9 |