473,666 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with gcc build - #including files

31 New Member
I have the following files:


netfunc.h:

Expand|Select|Wrap|Line Numbers
  1. typedef struct{
  2.      char data[MAX];
  3.      int n;
  4. }packet;
  5.  
  6. typedef struct
  7. {
  8.      char flag_s;
  9.      char address;
  10.      unsigned char control;
  11.      char data[MAX];
  12.      unsigned char FCS1;
  13.      unsigned char FCS2;
  14.      char flag_e;
  15. }frame;
  16.  
  17. typedef struct{
  18.     frame trama;
  19.     packet paquete;
  20.     FILE* file;
  21.     int tty;
  22. }arguments;
  23.  
  24.  
  25. void to_physical_layer(frame *fr, int fds);
  26. void from_physical_layer(frame *fr, int fde);
  27. void print_frame(frame trama);
  28. void format_frame(frame *fs, packet ps,int control);
  29. void format_packet(frame fs, packet *ps);
  30. void to_network_layer (packet pr, FILE *pfs);
  31.  

TX_automat_SW.h

Expand|Select|Wrap|Line Numbers
  1. /* ----------------------------------------------------------- *
  2.  * Author: Luis Sieira García <email removed>
  3.  * Date: May 2007
  4.  * No rights reserved
  5.  * ----------------------------------------------------------- */
  6. #include <IFTI_P2_automat.h>
  7.  
  8. #define    REACHED_EOF        3
  9.  
  10.  
  11.  
  12. /* ------------------------------------------------------------ 
  13.  * State definitions
  14.  * ------------------------------------------------------------ */
  15. enum {
  16.     TX_STATE_INITIAL = AUTOMAT_INITIAL_STATE,
  17.     TX_STATE_READING,
  18.     TX_STATE_FRAMING,
  19.     TX_STATE_WAITING
  20. };
  21.  
  22. /* ------------------------------------------------------------ 
  23.  * Event definitions
  24.  * ------------------------------------------------------------ */
  25. enum {
  26.     TX_EV_OPERATIVE = 1,
  27.     TX_EV_READOK,
  28.     TX_EV_FRAMED,
  29.     TX_EV_TWOFRAMES,
  30.     TX_EV_ACK_RECEIVED,
  31. };
  32.  
  33. /* ------------------------------------------------------------ 
  34.  * Action definitions
  35.  * ------------------------------------------------------------ */
  36. TAutomat * TX_automat_SW_define( );
  37.  
  38. int read_data(    TEntity * inEntity,
  39.             TState inFromState,
  40.             TEvent inEvent,
  41.             TEventArgs * inArgs );
  42.  
  43. int manage_data(    TEntity * inEntity,
  44.             TState inFromState,
  45.             TEvent inEvent,
  46.             TEventArgs * inArgs );
  47.  
  48. int send_data_wait_response(    TEntity * inEntity,
  49.             TState inFromState,
  50.             TEvent inEvent,
  51.             TEventArgs * inArgs );
  52.  

TX_SW

Manage the automat transitions, so it includes "TX_automat_SW. h".

It needs to use some functions from netfunc.h

If I don't include netfunc.h I get

[...]
src/TX_SW.c: In function ‘main’:
src/TX_SW.c:25: error: ‘arguments’ undeclared (first use in this function)
[...]

if I include both

#include <TX_automat_SW. h>
#include <netfunc.h>

then functions are not defined in TX_automat_SW

[...]
./src/TX_automat_SW.o : In function `manage_data':
src/TX_automat_SW.c :80: referencia a `format_frame' sin definir
[...]


As I think, solution is related with #ifndef #ifdef and #endif directives, but I've never used it... and I don't know how to do it...
May 31 '07 #1
6 1773
RedSon
5,000 Recognized Expert Expert
TX_SW

Manage the automat transitions, so it includes "TX_automat_SW. h".

It needs to use some functions from netfunc.h

If I don't include netfunc.h I get

[...]
src/TX_SW.c: In function ‘main’:
src/TX_SW.c:25: error: ‘arguments’ undeclared (first use in this function)
[...]

if I include both

#include <TX_automat_SW. h>
#include <netfunc.h>

then functions are not defined in TX_automat_SW

[...]
./src/TX_automat_SW.o : In function `manage_data':
src/TX_automat_SW.c :80: referencia a `format_frame' sin definir
[...]


As I think, solution is related with #ifndef #ifdef and #endif directives, but I've never used it... and I don't know how to do it...
First off anything you include that is not part of the standard or platform SDK should be included with double quotes #include "netfunc.h" . Either your compiler will just ignore the difference between <> and "" or it will look in a different path.

So it looks like in your TX_automat_SW.c you are referencing something called "format_fra me" that is not visitable to TX_automat_SW. It doesnt have anything to do with the #ifdef #endif statements. You are missing a #include in either TX_automat_SW.c or TX_automat_SW.h .

¿entiendes?
May 31 '07 #2
Sieira
31 New Member
First off anything you include that is not part of the standard or platform SDK should be included with double quotes #include "netfunc.h" . Either your compiler will just ignore the difference between <> and "" or it will look in a different path.

So it looks like in your TX_automat_SW.c you are referencing something called "format_fra me" that is not visitable to TX_automat_SW. It doesnt have anything to do with the #ifdef #endif statements. You are missing a #include in either TX_automat_SW.c or TX_automat_SW.h .

¿entiendes?

Entiendo (o eso creo), gracias... But I couldn't solve my problem

I've replaced <> with "" around my .h files.

TX_automat_SW.c includes this:

Expand|Select|Wrap|Line Numbers
  1.      #include "TX_automat_SW.h"
  2.      #include "netfunc.h"
  3.  
  4.      #include <unistd.h>
  5.      #include <stdio.h>
  6.      #include <stdlib.h>
  7.      #include <string.h>
  8.  
When I run my make.

Expand|Select|Wrap|Line Numbers
  1. sieira@GATTACA:/DOCS/Mis documentos/Estudios pendientes/Teleinformatica/LABORATORIO/Practica II/Programas$ make
  2. gcc -g -c -Wall -I ./include src/IFTI_P2_automat.c -o src/IFTI_P2_automat.o
  3. gcc -g -c -Wall -I ./include src/TX_automat_SW.c -o src/TX_automat_SW.o
  4. gcc -g -c -Wall -I ./include src/TX_SW.c -o src/TX_SW.o
  5. src/TX_SW.c: In function ‘main’:
  6. src/TX_SW.c:26: error: ‘arguments’ undeclared (first use in this function)
  7. src/TX_SW.c:26: error: (Each undeclared identifier is reported only once
  8. src/TX_SW.c:26: error: for each function it appears in.)
  9. src/TX_SW.c:26: error: expected ‘;’ before ‘args’
  10. src/TX_SW.c:31: error: ‘frame’ undeclared (first use in this function)
  11. src/TX_SW.c:31: error: expected ‘;’ before ‘inFrame’
  12. src/TX_SW.c:32: error: ‘packet’ undeclared (first use in this function)
  13. src/TX_SW.c:32: error: expected ‘;’ before ‘inPacket’
  14. src/TX_SW.c:41: error: ‘MAX’ undeclared (first use in this function)
  15. src/TX_SW.c:41: error: ‘args’ undeclared (first use in this function)
  16. src/TX_SW.c:88: warning: implicit declaration of function ‘print_frame’
  17. src/TX_SW.c:92: warning: implicit declaration of function ‘from_physical_layer’
  18. src/TX_SW.c:92: error: ‘inFrame’ undeclared (first use in this function)
  19. src/TX_SW.c:93: error: ‘CONTROL’ undeclared (first use in this function)
  20. src/TX_SW.c:94: error: ‘ACK’ undeclared (first use in this function)
  21. src/TX_SW.c:96: warning: implicit declaration of function ‘format_packet’
  22. src/TX_SW.c:96: error: ‘inPacket’ undeclared (first use in this function)
  23. make: *** [src/TX_SW.o] Error 1
  24.  
(as you can see "gcc -g -c -Wall -I ./include src/TX_automat_SW.c -o src/TX_automat_SW.o " returns no errors)

Every error and warning refers to types and functions contained in "netfunc.h" , and called from TX_SW.c so i include it. Since this header is included in both (TX_automat_SW. c and TX_SW.c) files. What I get is this:

Expand|Select|Wrap|Line Numbers
  1. sieira@GATTACA:/DOCS/Mis documentos/Estudios pendientes/Teleinformatica/LABORATORIO/Practica II/Programas$ make
  2. gcc -g -c -Wall -I ./include src/IFTI_P2_automat.c -o src/IFTI_P2_automat.o
  3. gcc -g -c -Wall -I ./include src/TX_automat_SW.c -o src/TX_automat_SW.o
  4. gcc -g -c -Wall -I ./include src/TX_SW.c -o src/TX_SW.o
  5. gcc  ./src/IFTI_P2_automat.o ./src/TX_automat_SW.o ./src/TX_SW.o -o bin/TX_SW
  6. ./src/TX_automat_SW.o: In function `manage_data':
  7. src/TX_automat_SW.c:81: referencia a `format_frame' sin definir
  8. ./src/TX_automat_SW.o: In function `send_data_wait_response':
  9. src/TX_automat_SW.c:95: referencia a `to_physical_layer' sin definir
  10. ./src/TX_SW.o: In function `main':
  11. src/TX_SW.c:89: referencia a `print_frame' sin definir
  12. src/TX_SW.c:93: referencia a `from_physical_layer' sin definir
  13. src/TX_SW.c:96: referencia a `print_frame' sin definir
  14. src/TX_SW.c:97: referencia a `format_packet' sin definir
  15. src/TX_SW.c:110: referencia a `print_frame' sin definir
  16. src/TX_SW.c:114: referencia a `from_physical_layer' sin definir
  17. src/TX_SW.c:117: referencia a `print_frame' sin definir
  18. src/TX_SW.c:118: referencia a `format_packet' sin definir
  19. collect2: ld returned 1 exit status
  20. make: *** [bin/TX_SW] Error 1
  21.  
Now types get defined, and no error related is shown...but netfunc.h functions become undefined in both files...

I'm getting crazy...
May 31 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I would be going crazy too. I took your code and compiled it with Visual Studio.NET and got no errors.

I has to add this:

Expand|Select|Wrap|Line Numbers
  1. #define MAX 100
  2. #define AUTOMAT_INITIAL_STATE  100
  3. class TAutomat
  4. {
  5.  
  6. };
  7. class TEntity
  8. {
  9.  
  10. };
  11. class TState
  12. {
  13.  
  14. };
  15. class TEvent
  16. {
  17.  
  18. };
  19. class TEventArgs
  20. {
  21.  
  22. };
  23.  
just before the netfunc.h. I just made up values to see if it would compile.

My code looks like:

Expand|Select|Wrap|Line Numbers
  1. #define MAX 100
  2. #define AUTOMAT_INITIAL_STATE  100
  3. class TAutomat
  4. {
  5.  
  6. };
  7. class TEntity
  8. {
  9.  
  10. };
  11. class TState
  12. {
  13.  
  14. };
  15. class TEvent
  16. {
  17.  
  18. };
  19. class TEventArgs
  20. {
  21.  
  22. };
  23.         ///////////////////////////////////////////
  24.         //netfunc.h
  25.         typedef struct{
  26.      char data[MAX];
  27.      int n;
  28. }packet;
  29.  
  30. typedef struct
  31. {
  32.      char flag_s;
  33.      char address;
  34.      unsigned char control;
  35.      char data[MAX];
  36.      unsigned char FCS1;
  37.      unsigned char FCS2;
  38.      char flag_e;
  39. }frame;
  40.  
  41. typedef struct{
  42.     frame trama;
  43.     packet paquete;
  44.     FILE* file;
  45.     int tty;
  46. }arguments;
  47.  
  48.  
  49. void to_physical_layer(frame *fr, int fds);
  50. void from_physical_layer(frame *fr, int fde);
  51. void print_frame(frame trama);
  52. void format_frame(frame *fs, packet ps,int control);
  53. void format_packet(frame fs, packet *ps);
  54. void to_network_layer (packet pr, FILE *pfs);
  55.  
  56. ///////////////////////////////
  57. int main()
  58. {
  59.  
  60.  
  61.         ///////////////////////////////////////////
  62. /* ----------------------------------------------------------- *
  63. * Author: Luis Sieira García <email removed>
  64. * Date: May 2007
  65. * No rights reserved
  66. * ----------------------------------------------------------- */
  67. //#include <IFTI_P2_automat.h>
  68.  
  69. #define REACHED_EOF    3
  70.  
  71.  
  72.  
  73. /* ------------------------------------------------------------ 
  74. * State definitions
  75. * ------------------------------------------------------------ */
  76. enum {
  77.     TX_STATE_INITIAL = AUTOMAT_INITIAL_STATE,
  78.     TX_STATE_READING,
  79.     TX_STATE_FRAMING,
  80.     TX_STATE_WAITING
  81. };
  82.  
  83. /* ------------------------------------------------------------ 
  84. * Event definitions
  85. * ------------------------------------------------------------ */
  86. enum {
  87.     TX_EV_OPERATIVE = 1,
  88.     TX_EV_READOK,
  89.     TX_EV_FRAMED,
  90.     TX_EV_TWOFRAMES,
  91.     TX_EV_ACK_RECEIVED,
  92. };
  93.  
  94. /* ------------------------------------------------------------ 
  95. * Action definitions
  96. * ------------------------------------------------------------ */
  97. TAutomat * TX_automat_SW_define( );
  98.  
  99. int read_data(  TEntity * inEntity,
  100.             TState inFromState,
  101.             TEvent inEvent,
  102.             TEventArgs * inArgs );
  103.  
  104. int manage_data(    TEntity * inEntity,
  105.             TState inFromState,
  106.             TEvent inEvent,
  107.             TEventArgs * inArgs );
  108.  
  109. int send_data_wait_response(    TEntity * inEntity,
  110.             TState inFromState,
  111.             TEvent inEvent,
  112.             TEventArgs * inArgs );
  113.  
  114.  
  115.         /////////////////////////////////////////////////
  116.  
  117. }
May 31 '07 #4
Sieira
31 New Member
Thank you, I was not getting crazy. I was stupid...

I wondered "why didn't compile for me if the code has no errors?"

Obviously the problem was in my Makefile

Expand|Select|Wrap|Line Numbers
  1. CC=gcc
  2. CXX=gcc
  3. INCLUDES=-I ./include
  4. CFLAGS=-g -c -Wall
  5. LDFLAGS=
  6. SOURCES=./src/IFTI_P2_automat.c ./src/TX_automat_SW.c ./src/TX_SW.c
  7. OBJECTS=$(SOURCES:.c=.o)
  8. EXECUTABLE1=./bin/TX_SW
  9. EXECUTABLE2=./bin/RX_SW
  10.  
  11. all: $(SOURCES) $(EXECUTABLE1) $(EXECUTABLE2)
  12.  
  13. $(EXECUTABLE1): $(OBJECTS) 
  14.     $(CC) $(LDFLAGS) $(OBJECTS) -o $@
  15.  
  16. $(EXECUTABLE2): $(OBJECTS) 
  17.     $(CC) $(LDFLAGS) $(OBJECTS) -o $@
  18.  
  19. .c.o:
  20.     $(CC) $(CFLAGS) $(INCLUDES) $< -o $@
  21.  
  22. clean:
  23.     \rm -rf $(OBJECTS) $(EXECUTABLE1) $(EXECUTABLE2)
  24.  
I forgot to add ./src/netfunc.c in the SOURCES tag!!!

I don't use to write Makefiles this way... so I didn't see it.

Thousands of thanks
May 31 '07 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
You gotta trade that thing in for an IDE that does the makefiles for you.
May 31 '07 #6
Banfa
9,065 Recognized Expert Moderator Expert
You gotta trade that thing in for an IDE that does the makefiles for you.
You know that sometimes you just don't get a choice, particularly if you want to do management of multi-platform code.

Most platforms compilers do not come with an IDE.
May 31 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
2420
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line, the compilation seems to work properly almost all of the time. More on this later. If I launch one copy of the IDE, then I can usually compile the project at least once. At some point, the build fails reporting "Could not copy temporary files...
6
2300
by: Alan Krueger | last post by:
Is there a way to automatically include C# files (.cs) generated by a third-party tool into a Visual C# .NET build? It's possible the set of files generated by this tool might change. Adding these files manually to the project would work in the short term, but this would require manual intervention if these generated files happened to change, and I'd like to avoid any unnecessary manual steps. NAnt and similar tools can include and...
3
1887
by: Brian Henry | last post by:
This has worked perfectly for the past year now all the sudden it will not compile the installer project correctly. All our source code is in a Source Safe database so every system we do this on should be identicle. On one system the installer project will compile correctly, but on two others it will fail with this error. ------ Rebuild All started: Project: Installer, Configuration: Debug ------ Building file 'T:\Current Builds...
5
2061
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our Active Directory on a web page. If I can connect to the AD interfaces, then I think I can handle it from there. I do have a VS.NET C# project successfully working and enumerating names,
2
3497
by: shruti | last post by:
hiii all I'm tryin to call a perl script from a C program in following 2 ways- 1.By callin system function. But there's some problem because the system function is not able to executeany command...it just returns -1. 2.By using the code given in perldoc perlembed(perl documentation for embedding perl in C)
0
891
by: rohinichandrap | last post by:
Hi, I am facing a strange problem with the .pdb files in one of the project workspaces I am working with.This is during an upgrade from Visual studio 6.0 to Visual Studio .Net 2003. The workspace has two projects A,B. When I build project A it asks for a checkout of the B.pdb file along with A.exe,.map,.pdb. When I build project B it asks for a checkout of the A.pdb file along
0
1639
by: anupamak | last post by:
hello, I created a win32 project(precompiled headers, console application). This was created to create a service( for which i used SERVICE_TABLE_ENTRY, SERVICE_STATUS, SERVICE_STATUS_HANDLE, etc... required structures and methods). Environment used: Windows XP, VC++.Net2005. Should work on: I want to make this exe to run on windows 95,98, XP, 2000 and Vista.
11
2563
by: ZMY | last post by:
Dear all, I am a real newbie for both python and QNX, but I am still trying to compile Numeric-24.2 under QNX4.25 with python 2.2. I got following error message: $ sudo python setup.py install Password: running install
0
2108
by: james.mcdonagh | last post by:
Hi I am a newbie using nAnt for .net 2.0. As such I have not come across this bug before, and I would be happy of any help that you may be able to provide. In order to help I have included the nant file which is causing the problem, the object code that is not being built and the error message which is being produced. The weird thing is that VS.net builds without a problem. And the intellisense within the object WorkQueue knows that...
14
11782
by: yxq | last post by:
Hello, I want to build the multi-language application with the xml file, how to do? could anyone tell a sample? Thank you
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.