473,508 Members | 2,367 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 1759
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_frame" 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_frame" 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
2405
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,...
6
2287
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...
3
1877
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...
5
2050
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...
2
3472
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...
0
885
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...
0
1620
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,...
11
2542
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...
0
2102
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...
14
11764
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
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7039
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...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
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,...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.