CodeBlocks

Fermé
mouzill - Modifié par mouzill le 25/12/2013 à 13:34
 mouzill - 26 déc. 2013 à 14:24
Bonjour,

je fais maintenant un petit programme avec gnu C sous CodeBlocks. le code est le suivant:
fichier header.h:

#define CHECK_FORMAT __attribute__ ((format1 (printf, 1, 2)))

extern void eprintf(const char *format1, ...) CHECK_FORMAT;

fichier Untitled1.c:
#include <stdio.h>
#include <stdarg.h>
#include "header.h"


void foo()
{
eprintf("file %s does not exist\n", "file"); /* error on this line */


printf("n=%d,%d,%d\n", 1, 2, 3);
}

int main(int argc, char** argv)
{
foo();
return 0;
}


Sous codeBlocks le compiler me fait une erreur qui est la suivante:

mingw32-gcc.exe -O -Wall -ansi -g -c "C:\Documents and Settings\Mohamed\Bureau\Untitled1.c" -o "C:\Documents and Settings\Mohamed\Bureau\Untitled1.o"
In file included from C:\Documents and Settings\Mohamed\Bureau\Untitled1.c:3:0:
C:\Documents and Settings\Mohamed\Bureau\header.h:3:1: warning: 'format1' attribute directive ignored [-Wattributes]
mingw32-g++.exe -o "C:\Documents and Settings\Mohamed\Bureau\Untitled1.exe" "C:\Documents and Settings\Mohamed\Bureau\Untitled1.o"
C:\Documents and Settings\Mohamed\Bureau\Untitled1.o: In function 'foo':
C:/Documents and Settings/Mohamed/Bureau/Untitled1.c:8: undefined reference to 'eprintf'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 1 warnings (0 minutes, 0 seconds)

Merci bien

5 réponses

fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 836
26 déc. 2013 à 08:37
Bonjour,

Pour info, __attribute__ n'est pas portable.
Sinon, tu utilises la fonction eprintf() mais tu nous dis pas où se trouve le code ? Dans une bibliothèque ? Dans un autre fichier ? Comment fais-tu la compilation ?
0
salut,

voila ce sont simplement deux fichiers Untitled1.c et header.h.
J'appuie sur build puis sur run sous codeblocks il me fait sortir ces lignes suivantes :

mingw32-gcc.exe -O -Wall -ansi -g -c "C:\Documents and Settings\Mohamed\Bureau\Untitled1.c" -o "C:\Documents and Settings\Mohamed\Bureau\Untitled1.o"
In file included from C:\Documents and Settings\Mohamed\Bureau\Untitled1.c:3:0:
C:\Documents and Settings\Mohamed\Bureau\header.h:3:1: warning: 'format1' attribute directive ignored [-Wattributes]
mingw32-g++.exe -o "C:\Documents and Settings\Mohamed\Bureau\Untitled1.exe" "C:\Documents and Settings\Mohamed\Bureau\Untitled1.o"
C:\Documents and Settings\Mohamed\Bureau\Untitled1.o: In function 'foo':
C:/Documents and Settings/Mohamed/Bureau/Untitled1.c:8: undefined reference to 'eprintf'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 1 warnings (0 minutes, 0 seconds)

Le code de eprintf est le suivant dans header.h tout simplement le format de printf:

#define CHECK_FORMAT __attribute__ ((format1 (printf, 1, 2)))
extern void eprintf(const char *format1, ...) CHECK_FORMAT;

Merci pour toute aide ...
0
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 836
26 déc. 2013 à 10:52
Le code de eprintf est le suivant dans header.h tout simplement le format
Ca ce n'est pas le code. Il s'agit du prototype. Le code se trouve soit dans un .c qu'il convient de compiler également et de linker au moment de la compilation (phase édition des liens) soit le code se trouve dans une bibliothèque qu'il convient de linker.
0
après une rapide recherche je trouve:

eprintf.c   [plain text]
/* ===---------- eprintf.c - Implements __eprintf --------------------------===
 *
 *                     The LLVM Compiler Infrastructure
 *
 * This file is dual licensed under the MIT and the University of Illinois Open
 * Source Licenses. See LICENSE.TXT for details.
 *
 * ===----------------------------------------------------------------------===
 */



#include "int_lib.h"
#include <stdio.h>
#include <stdlib.h>


/*
 * __eprintf() was used in an old version of <assert.h>.
 * It can eventually go away, but it is needed when linking
 * .o files built with the old <assert.h>.
 *
 * It should never be exported from a dylib, so it is marked
 * visibility hidden.
 */
__attribute__((visibility("hidden")))
void __eprintf(const char* format, const char* assertion_expression,
				const char* line, const char* file)
{
	fprintf(stderr, format, assertion_expression, line, file);
	fflush(stderr);
	compilerrt_abort();
}


Mais je ne pense passe pas que cela correspond à ta fonction!

regarde si elle existe sur ton fichier Untitled1.c.
0
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 836
26 déc. 2013 à 11:34
Ca n'existe pas dans son fichier Untitled1.c vu le message d'erreur.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
j'ai copié ce code de l'internet. Je veux comprendre seulement le fonctionnement de __attribute__ et le site est le suivant :
http://www.unixwiz.net/techtips/gnu-c-attributes.html
0