Unterminated ifndef ошибка

The #ifdef should be a #define for you to have working #include guard. As originally written the #ifndef is missing the matching #endif.

Symbols that start with underscore followed by an uppercase letter are reserved (6.4.2.1). Use MAIN_H instead.

You could also use #pragma once which is a non-standard, but widely supported, alternative to the include guard.

Leave out the ~ of the code listing as it’s vi’s EOF marker and not part of your header file.


Recommended Answers

Make sure there is a carriage return at the end of the last line.
Some compilers are picky.

Jump to Post

Hi,I spent all night trying to figure this out. Could someone take a look and show me what I’m missing? I getting this compiler error: unterminated #ifndef . But I have ifndef at the beginning and endif at the end of the class.

//Header file. 
//Class definition for …

Jump to Post

All 5 Replies

Member Avatar


thines01

401



Postaholic



Team Colleague



Featured Poster


11 Years Ago

Make sure there is a carriage return at the end of the last line.
Some compilers are picky.

Member Avatar

11 Years Ago

Hi,I spent all night trying to figure this out. Could someone take a look and show me what I’m missing? I getting this compiler error: unterminated #ifndef . But I have ifndef at the beginning and endif at the end of the class.

//Header file. 
//Class definition for teh stack ADT

#ifndef _mystack_H
#include <ostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _mystack_H


const unsigned int maxSize = 10;

class Stack
{
      public:
                Stack(); //constructor
      
                ~Stack(); //Destructor

                bool isEmptyStack();
                
                bool isFullStack();
                
                void pushStack(int newItem);
                
                void popStack(int item);
                
                void initializeStack();
                
                void fillStack(int numSize);
                
                void exchangeTopAndBottom(Stack &stk);
                
                void printStack(Stack &stk);
                
                int sumStack(Stack &stk);
                
                void OddElem(Stack &stk);
                
                //void commonStack(Stack &stk1, Stack &stk2);
                
                void intersectStack(Stack &stk1, Stack &stk2);

       private:
                int maxSize;  //variable to store the maximum stack size
                int stackTop; //variable to poit to the top of the stack
                Stack arrList;//pointer to the array that holds the stack 
                              //elements
        
};      

#endif

First of all, «Stack arrList» —this is not legal as far as I know in C++. This should be Stack* arrlist. Fix this first and try it.

I’m not sure about your #ifndef problem. I copy/pasted your code and it compiled after I fixed the Stack*. My guess is that it’s one of your overlapping includes that’s not being properly handled by your particular compiler.

fstream automatically includes ostream. Here’s a map of how that works:
http://www.cplusplus.com/reference/iostream/
Anything that an arrow points to, will automatically include its parent class, tracing backwards. So you only need to include fstream. First remove #include <ostream> and try to compile. Pretty sure stdio automatically includes stdlib, too. You should try to remove one or the other. Stdio is C input output. In my opinion you shouldn’t use both the C++ streams library and the Stdio library, as they both perform similar tasks.

You should #include as few things as possible. Not only does it bloat your code, but it can confuse your compiler as well.

Edited

11 Years Ago
by Greywolf333 because:

n/a

Member Avatar


LevyDee

2



Posting Whiz in Training


11 Years Ago

You need to format your defines as such:
#ifndef
#define

#endif

after you said #ifndef _mystack_H
you need to then put a #define right after that on line 5

Member Avatar


murnesty

0



Junior Poster in Training


11 Years Ago

It may caused by previous header file

Member Avatar


BoBok2002

0



Junior Poster in Training


11 Years Ago

It worked! I repositioned the ifndef, define, and endif. Then I changed #include <ostream> to #include <iostream> and I compiled the code on a different compiler, and it worked. I fixed the Stack *arrList too.

Now I’m getting another error. The last one I hope. It says

[Linker error] undefined reference to `Stack::Stack()’

And there is a linker error displayed for all the functions in my implementation file. Also, #include «mystack.h» has been highlighted in both the main and implementation file. Please help me with this one too.
Thanks.


Reply to this topic

Be a part of the DaniWeb community

We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.

  • Forum
  • Beginners
  • error : unterminated #ifndef

error : unterminated #ifndef

Hey, umm I’m a beginner at c++ and have no idea why this error is happening :(

error : unterminated #ifndef

Burrito2.h

1
2
3
4
5
6
7
8
9
10
11
12
1 #ifndef BURRITO2_H
2 #define BURRITO2_H
3 
4 
5 class Burrito2
6 {
7     public:
8         Burrito2();
9         
10 };
11 
12 #endif // BURRITO2_H 

main.cpp

1
2
3
4
5
6
7
8
9
1 #include <iostream>
2 #include "Burrito2.h"
3 using namespace std;
4
5 int main()
6 {
7     Burrito2 bo;
8     return 0;
9 }

Burrito2.cpp

1
2
3
4
5
6
7
8
9
1 #include "Burrito2.h"
2 #include <iostream>
3
4 using namespace std;
5
6 Burrito2::Burrito2()
7 {
8     cout << "i am a banana" << endl;
9 }

Last edited on

Does the compiler state the file, where error occurs?

Hello sohui,

In addition to keskiverto‘s question are the line numbers in the files?

When I loaded up your files in my IDE, (VS2017), minus the line numbers I could not duplicate your error.

Not sure what you did using the code tags, but they do not put the line numbers in side the block unless you copy a pasted it that way.

In «Burrito2.cpp» you have:

1
2
#include "Burrito2.hpp"
#include <iostream> 

Sometimes this will make no difference, but at other times it does. I tend to like this order better.

1
2
3
#include <iostream>

#include "Burrito2.hpp" 

I like the «.hpp»extension better than the «.h» extension when using a C++ program. The «.h» makes me think it is a C header file when it is not.

With «Burrito2.hpp» being last the header file(s) that come before are compiled first and anything in the «Burrito2.hpp» file that would need the above header files is covered. I use the blank line to break the standard include files the ones in the (<>)s from the files that I would write, the ones in («»)s.

Hope that helps,

Andy

I was able to run code without errors and didn’t edit the files. Maybe try BURRITO2_H_.

Topic archived. No new replies allowed.

Есть два класса, которые связаны друг с другом в своих заголовках:

PlotMarker

#ifndef PLOTMARKER_H
#define PLOTMARKER_H

#include <QObject>
#include "plotter.h"
class Plotter;

class PlotMarker : public QObject
{
// ...
Plotter* m_attachedPlot;
// ...
};

#endif // PLOTMARKER_H

графопостроитель

#ifndef PLOTTER_H
#define PLOTTER_H

// ...
#include "plotmarker.h"// ...

class PlotMarker;

class Plotter : public QQuickPaintedItem
{
// ...
QLinkedList<PlotMarker*> m_markerList;
// ...
};

#endif // PLOTTER_H

Программа скомпилирована хорошо, но есть ошибка error: unterminated conditional directive в #ifndef и код классов в IDE не выделяется из-за этого.

Если я удалю #include "plotter.h" в заголовке PlotMarker или #include "plotmarker.h" в заголовке Plotter Qt Creator подсвечивает код как обычно, но компиляция завершается неудачно из-за ошибок о недопустимом использовании неполного типа.

Не могли бы вы сказать мне, что не так? Я думаю, что это из-за неправильных перекрестных ссылок заголовков, но я столкнулся с этот и это не помогло мне.

1

Решение

Проблема решена.

Я только что переехал один из #include из заголовка в исходный файл, и это сработало.

plotmarker.h

#ifndef PLOTMARKER_H
#define PLOTMARKER_H

#include <QObject>

class Plotter;

class PlotMarker : public QObject
{
// ...
Plotter* m_attachedPlot;
// ...
};

#endif // PLOTMARKER_H

// …

plotmarker.cpp

#include "plotmarker.h"#include "plotter.h"// ...

2

Другие решения

Других решений пока нет …

Use Buildroot from v2021.02.1 release (https://buildroot.org/downloads/buildroot-2021.02.1.tar.gz) with the following defconfig:

BR2_arcle=y
BR2_archs38=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2021.03-rc2/arc_gnu_2021.03-rc2_prebuilt_glibc_le_archs_linux_install.tar.gz"
BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_1=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_DEFCONFIG="haps_hs"
BR2_LINUX_KERNEL_VMLINUX=y
BR2_TARGET_ROOTFS_INITRAMFS=y

Extract «native» tools (https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2021.03-rc2/arc_gnu_2021.03-rc2_prebuilt_glibc_le_archs_native_install.tar.gz) in outpup/target folder & rebuild vmlinux with make command.

Boot on the target, for example nSIM:

nsimdrv -prop=nsim_isa_family=av2hs -prop=nsim_isa_core=3 -prop=chipid=0xffff 
-prop=nsim_isa_atomic_option=1 -prop=nsim_isa_ll64_option=1 -prop=nsim_mmu=4 
-prop=mmu_pagesize=8192 -prop=mmu_super_pagesize=2097152 -prop=mmu_stlb_entries=16 
-prop=mmu_ntlb_ways=4 -prop=mmu_ntlb_sets=128 -prop=icache=32768,64,4,0 
-prop=dcache=16384,64,2,0 -prop=nsim_isa_shift_option=3 -prop=nsim_isa_swap_option=1 
-prop=nsim_isa_bitscan_option=1 -prop=nsim_isa_sat=1 -prop=nsim_isa_div_rem_option=2 
-prop=nsim_isa_mpy_option=9 -prop=nsim_isa_enable_timer_0=1 -prop=nsim_isa_enable_timer_1=1 
-prop=nsim_isa_number_of_interrupts=32 -prop=nsim_isa_number_of_external_interrupts=32 
-prop=isa_counters=1 -prop=nsim_isa_pct_counters=8 -prop=nsim_isa_pct_size=48 
-prop=nsim_isa_pct_interrupt=1 -prop=nsim_mem-dev=uart0,kind=dwuart,base=0xf0000000,irq=24 
-prop=nsim_isa_aps_feature=1 -prop=nsim_isa_num_actionpoints=4 -prop=nsim_isa_rtc_option=1 
-prop=nsim_isa_ad_option=1 -prop=nsim_isa_fpud_div_option=1 -prop=nsim_isa_fpu_mac_option=1 
output/images/vmlinux -prop=nsim_fast=1

On target cd into extracted «native» toolchain location and:

$ cat <<EOF > hello_world.c
#include <stdio.h>
int main(void)
{
        printf("Hello worldn");
        return 0;
}
EOF

# $ ./gcc hello_world.c
In file included from /glibc_le_archs_native/arc-snps-linux-gnu/sysroot/usr/include/stdio.h:33,
                 from hello_world.c:1:
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:245: error: unterminated #ifndef
  245 | #ifndef _WCHAR_T
      |
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:244: error: unterminated #ifndef
  244 | #ifndef __WCHAR_T__ /* Cray Unicos/Mk */
      |
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:243: error: unterminated #ifndef
  243 | #ifndef __wchar_t__ /* BeOS */
      |
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:242: error: unterminated #if
  242 | #if defined (_STDDEF_H) || defined (__need_wchar_t)
      |
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:45: error: unterminated #ifndef
   45 | #ifndef __sys_stdtypes_h
      |
/glibc_le_archs_native/lib/gcc/arc-snps-linux-gnu/10.2.0/include/stddef.h:27: error: unterminated #if
   27 | #if (!defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_ANSI_STDDEF_H) 
      |

Понравилась статья? Поделить с друзьями:
  • Unsupported command 7 zip ошибка
  • Unsupported alpine ошибка
  • Unrouteable address ошибка почты
  • Unresolved reference python ошибка
  • Unrecognized upnp response ошибка upnp wizard