I’m compiling a project in XCode where MySQL++ in included and linked to. For some reason, I keep getting the following compiler error:
‘assert’ was not declared in this scope
originating from cpool.h, a header file that’s part of MySQL++. Does anyone know why this is being triggered?
EDIT: For reference, MySQL++ was installed via Macports.
asked May 25, 2010 at 22:45
AnonymousAnonymous
1,7103 gold badges16 silver badges21 bronze badges
3
The most obvious answer would be that «assert.h» is not being included or is not being found in your include path. Another explanation is that the assert macro has been undefined at some point after the header was included.
Edit: Since you say that assert.h is included, and we’ll assume for the moment that it’s being found since it’s a standard header, then that leaves us with the last possibility I stated above i.e. that the macro has been undefined.
Since cpool.h itself will not be doing this it must be the case that assert.h is included earlier either by yourself or indirectly by another 3rd party header and the undefining happening between this and your inclusion of cpool.h. This can easily be tested by moving your cpool.h include to the top of your file.
answered May 25, 2010 at 22:55
TroubadourTroubadour
13.2k2 gold badges37 silver badges57 bronze badges
9
In c++ adding cassert header should fix your problem.
#include <cassert>
answered Mar 9, 2016 at 14:16
MBIMBI
5738 silver badges22 bronze badges
It could be that another library in your include path has a different «assert.h» file, and you are unknowingly including that one instead of the system’s standard <assert.h>.
I ran into this issue when writing an application that uses gstreamer on Mac OSX. It turns out that gstreamer’s include directory (/Library/Frameworks/GStreamer.framework/Headers) includes a file «assert.h», which is non-standard and an unsuitable replacement for the real assert.h. When I added -I/Library/Frameworks/GStreamer.frameworks/Headers to my compilation command, suddenly my sources, which just said «#include <assert.h>» where including the gstreamer version. This caused my compilation to fail with the same error you were getting.
answered Jul 9, 2013 at 19:55
Greg PrisamentGreg Prisament
2,1461 gold badge16 silver badges18 bronze badges
SergeyKagen 3 / 4 / 2 Регистрация: 02.04.2018 Сообщений: 315 |
||||
1 |
||||
19.04.2019, 22:16. Показов 131570. Ответов 14 Метки нет (Все метки)
Простой код, но Arduino IDE напрочь отказывается принимать переменные. Что за глюк или я что-то неправильно делаю?
ошибка при компиляции «‘count’ was not declared in this scope», что не так?
__________________
0 |
marat_miaki 495 / 389 / 186 Регистрация: 08.04.2013 Сообщений: 1,688 |
||||
19.04.2019, 23:26 |
2 |
|||
Сообщение было отмечено SergeyKagen как решение Решение
1 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||||||
14.09.2019, 22:33 |
3 |
|||||||
Доброго времени суток!
В loop() делаю вызов:
При компиляции выделяется этот вызов, с сообщением: ‘myDisplay’ was not declared in this scope Замучился искать инфу о декларации/обьявлении функции. Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции P.S. Код, что использовал в качестве функции, работоспособен. Раньше находился в loop(). Скетч постепенно разрастается, много однотипных обращений к дисплею…
0 |
8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
|
14.09.2019, 23:57 |
4 |
Создал функцию (за пределами setup и loop), Перевидите на нормальный язык. В другом файле что ли? Добавлено через 1 минуту
Замучился искать инфу о декларации/обьявлении функции. Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции Читать учебники по С++ не пробовали? https://metanit.com/cpp/tutorial/3.1.php Специфика Arduino лишь отличается тем что пред объявления не всегда нужны. Добавлено через 7 минут
0 |
ValeryS Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
||||
15.09.2019, 00:09 |
5 |
|||
Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции это где ж такое написано?
а объявить уже в удобном месте
0 |
0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
|
15.09.2019, 00:48 |
6 |
Неделю назад ВПЕРВЫЕ включил Arduino Uno. Написал на том же языке, что и читал на всяких форумах и справочниках по Arduino :-). За пределами этих функций — значит не внутри них. Обе приведенных Вами ссылок просмотрел, проверил в скетче… В итоге вылезла другая ошибка: void myDisplay(byte x, byte y, char str) тоже пробовал. Та же ошибка. Что не так на этот раз?
0 |
Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
|
15.09.2019, 01:26 |
7 |
В итоге вылезла другая ошибка: точку с запятой в конце поставил?
1 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||||||||||
15.09.2019, 08:46 |
8 |
|||||||||||
Вот скетч. Проще некуда.
Любое из трех так называемых «объявлений» (строки 7…9) выдает одну и ту же ошибку — я пытаюсь объявить функцию как переменную. Добавлено через 9 минут
Компилятор задумался (я успел обрадоваться), но, зараза :-), он снова поставил свой автограф undefined reference to `myDisplay(unsigned char, unsigned char, char, float) На этот раз он пожаловался на строку вызова функции. Добавлено через 34 минуты
Dispay вместо Display Добавлено через 8 минут
0 |
ValeryS Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
||||||||
15.09.2019, 10:36 |
9 |
|||||||
void myDisplay(byte, byte, char, float) = 0; вот так не надо делать(приравнивать функцию к нулю) Добавлено через 5 минут
void myDispay(byte x, byte y, char str, float temp)
myDisplay(0, 0, «C», temp); просишь чтобы функция принимала символ
или проси передавать строку, например так
1 |
Avazart 8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
||||
15.09.2019, 12:02 |
10 |
|||
Кроме того наверное лучше так:
Тогда можно будет вынести ф-цию в отдельный файл/модуль.
1 |
locm |
15.09.2019, 21:07
|
Не по теме:
Arduino Uno.
AVR (Basic, немного Assembler). Arduino Uno это AVR, для которого можете писать на бейсике или ассемблере.
0 |
Avazart |
15.09.2019, 21:21
|
Не по теме:
Arduino Uno это AVR, для которого можете писать на бейсике или ассемблере. Но лучше не надо …
0 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||
16.09.2019, 12:12 |
13 |
|||
это где ж такое написано? Оказалось, что я верно понял чтиво по справочникам:
вот так не надо делать(приравнивать функцию к нулю)… Методом проб и ошибок уже понял :-).
или передавай символ… Если передаю в одинарных кавычках более одного символа, а функция ждет как
или проси передавать строку, например так… Буквально вчера попалось это в справочнике, но как-то не дошло, что тоже мой вариант :-).
Кроме того наверное лучше так:
Тогда можно будет вынести ф-цию в отдельный файл/модуль. Благодарю за совет! Как-нибудь проверю…
0 |
8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
|
16.09.2019, 12:54 |
14 |
Оказалось, что я верно понял чтиво по справочникам: если ты вызываешь функцию, это и есть обьявление функции Нафиг выкиньте эти справочники.
0 |
0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
|
16.09.2019, 13:00 |
15 |
Ссылки Ваши добавлены в закладки. Время от времени заглядываю.
0 |
Open
Issue created Dec 16, 2018 by ax trifonov@otaku1
[regression] error: ‘assert’ was not declared in this scope
...
In file included from /tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.cpp:1:
/tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.h: In member function 'void GsTexture::unload()':
/tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.h:139:9: error: 'assert' was not declared in this scope
assert(mpTexture != nullptr);
^~~~~~
/tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.h:139:9: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
/tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.h:8:1:
+#include <cassert>
/tmp/makepkg/commander-genius-git/src/Commander-Genius/GsKit/graphics/GsTexture.h:139:9:
assert(mpTexture != nullptr);
^~~~~~
Arch Linux, commander-genius-git package from AUR
Description
Jack Howarth
2010-09-11 01:28:07 UTC
The new g++.dg/torture/pr44972.C fails to compile at all optimization levels on x86_64-apple-darwin10... FAIL: g++.dg/torture/pr44972.C -O0 (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O1 (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O2 (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O3 -fomit-frame-pointer (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O3 -g (test for excess errors) FAIL: g++.dg/torture/pr44972.C -Os (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O2 -flto (test for excess errors) FAIL: g++.dg/torture/pr44972.C -O2 -fwhopr (test for excess errors) The failures are of the form... /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../g++ -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../ /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/gcc/testsuite/g++.dg/torture/pr44972.C -nostdinc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include/x86_64-apple-darwin10.5.0 -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/testsuite/util -fmessage-length=0 -O0 -S -m32 -o pr44972.s /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/gcc/testsuite/g++.dg/torture/pr44972.C: In member function ‘const T* boost::optional<T>::operator->() const [with T = std::pair<NT, NT>]’: /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/gcc/testsuite/g++.dg/torture/pr44972.C:137:9: instantiated from here /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/gcc/testsuite/g++.dg/torture/pr44972.C:77:35: error: ‘__assert_fail’ was not declared in this scope Using built-in specs. COLLECT_GCC=g++-4 COLLECT_LTO_WRAPPER=/sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin10.5.0/4.6.0/lto-wrapper Target: x86_64-apple-darwin10.5.0 Configured with: ../gcc-4.6-20100910/configure --prefix=/sw --prefix=/sw/lib/gcc4.6 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.6/info --enable-languages=c,c++,fortran,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.6 --enable-checking=yes Thread model: posix gcc version 4.6.0 20100910 (experimental) (GCC)
Comment 1
Jack Howarth
2010-09-11 01:29:47 UTC
Created attachment 21770 [details]
preprocessed source for g++.dg/torture/pr44972.C -O0
Generated with...
/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../g++ -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../ /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/gcc/testsuite/g++.dg/torture/pr44972.C -nostdinc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include/x86_64-apple-darwin10.5.0 -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100910/libstdc++-v3/testsuite/util -fmessage-length=0 -O0 -S -m32 --save-temps -o pr44972.s
on x86_64-apple-darwin10.
Comment 2
Rainer Orth
2010-09-13 16:43:59 UTC
Same on *-*-solaris2* (probably on all non-Linux targets).
Comment 3
Jonathan Wakely
2010-09-13 17:04:52 UTC
the test already includes <cassert> so presumably the fix is simply to replace line 77 with T const* operator->() const { assert(this->is_initialized()) ; return this->get_ptr_impl() ; }
Comment 4
Paolo Carlini
2010-09-13 17:12:25 UTC
I agree with Jon: the expansion of assert to __assert_fail, etc, isn't portable, the testcase should simply use assert.
Comment 5
Jack Howarth
2010-09-13 19:13:16 UTC
I can confirm that the change... Index: gcc/testsuite/g++.dg/torture/pr44972.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr44972.C (revision 164251) +++ gcc/testsuite/g++.dg/torture/pr44972.C (working copy) @@ -74,7 +74,7 @@ T const& get() const ; - T const* operator->() const { ((this->is_initialized()) ? static_cast<void> (0) : __assert_fail ("this->is_initialized()", "pr44972.C", 78, __PRETTY_FUNCTION__)) ; return this->get_ptr_impl() ; } + T const* operator->() const { assert(this->is_initialized()) ; return this->get_ptr_impl() ; } } ; ...eliminates the g++.dg/torture/pr44972.C -O0 failures on x86_64-apple-darwin10 at both -m32 and -m64.
Comment 6
Paolo Carlini
2010-09-13 21:01:48 UTC
Please properly post the patch to the mailing list and let's resolve this rather straightforward issue. Thanks.
Comment 8
Martin Jambor
2010-09-14 11:53:08 UTC
Sorry, I messed up when I tried to remove includes from the testcase. Thanks for fixing it.
# (отредактировано 5 лет, 6 месяцев назад) |
|
Темы: 47 Сообщения: 11417 Участник с: 17 февраля 2013 |
Потверждаю, собирается без проблем — устанавливать не стал
Ошибки не исчезают с опытом — они просто умнеют |
Aoizora |
# |
Темы: 7 Сообщения: 39 Участник с: 13 июля 2017 |
Господа, libodb я собрал. Проблема со сборкой libodb-qt! Мои последние посты именно об этом. Я просто не стал начинать новую тему. |
vasek |
# |
Темы: 47 Сообщения: 11417 Участник с: 17 февраля 2013 |
Просто я не до конца скопировал — сейчас довел до конца, с установкой
Ошибки не исчезают с опытом — они просто умнеют |
Aoizora |
# |
Темы: 7 Сообщения: 39 Участник с: 13 июля 2017 |
А у меня не собирается. Как можно указать QtCore и к каким файлам Qt надо указывать пути? |
serg66 |
# |
Темы: 0 Сообщения: 91 Участник с: 01 ноября 2016 |
А у меня тоже собирается… |
vasek |
# |
Темы: 47 Сообщения: 11417 Участник с: 17 февраля 2013 |
Ты слишком много собирал ручками и устанавливал без pacman, плюс к этому не обновлялся целый год. И там сейчас не Arch, а солянка. Ошибки не исчезают с опытом — они просто умнеют |
vasek |
# (отредактировано 5 лет, 6 месяцев назад) |
Темы: 47 Сообщения: 11417 Участник с: 17 февраля 2013 |
Небольшое дополнение. LDFLAGS и CPPFLAGS — используются если имеются нестандартные пути размещения
И один из способов их применения
Для нормальной системы все пути стантартизованы и используя pacman или AUR ничего этого не нужно, все найдется автоматом. PS … посмотри этот топик, где Natrio дал ссылку как он использовал это для лечения конкретного пакета Ошибки не исчезают с опытом — они просто умнеют |
Aoizora |
# |
Темы: 7 Сообщения: 39 Участник с: 13 июля 2017 |
Статья про Qt на вики не помогла. Запустил сборку так:
Получаю ошибку:
Может, я указываю не те директории? Директории с либами пытался искать в /lib и в /usr/lib — безуспешно. Есть ли способ определить, где находятся инклуды и либы конкретной версии qt? |
Aoizora |
# |
Темы: 7 Сообщения: 39 Участник с: 13 июля 2017 |
Поможет ли переустановка Qt5 и насколько опасно ломать зависимости, например, sddm?
|
RusWolf |
# |
Темы: 11 Сообщения: 2413 Участник с: 16 июля 2016 |
Aoizora, как ты устанавливаешь пакеты из AUR ? |
Example
This error happens if a unknown object is used.
Variables
Not compiling:
#include <iostream>
int main(int argc, char *argv[])
{
{
int i = 2;
}
std::cout << i << std::endl; // i is not in the scope of the main function
return 0;
}
Fix:
#include <iostream>
int main(int argc, char *argv[])
{
{
int i = 2;
std::cout << i << std::endl;
}
return 0;
}
Functions
Most of the time this error occurs if the needed header is not
included (e.g. usingstd::cout
without#include <iostream>
)
Not compiling:
#include <iostream>
int main(int argc, char *argv[])
{
doCompile();
return 0;
}
void doCompile()
{
std::cout << "No!" << std::endl;
}
Fix:
#include <iostream>
void doCompile(); // forward declare the function
int main(int argc, char *argv[])
{
doCompile();
return 0;
}
void doCompile()
{
std::cout << "No!" << std::endl;
}
Or:
#include <iostream>
void doCompile() // define the function before using it
{
std::cout << "No!" << std::endl;
}
int main(int argc, char *argv[])
{
doCompile();
return 0;
}
Note: The compiler interprets the code from top to bottom (simplification). Everything must be at least declared (or defined) before usage.
Tips: If you need C++ homework help from experts, you can always rely upon assignment helpers.
Hi there,
I’ve been trying to compile the stub_mm included with the metamod source files but I can’t seem to get around errors relating to static_assert
Code:
In file included from ../core/sourcehook/sourcehook.h:118:0, from ../core/ISmmPlugin.h:37, from stub_mm.h:18, from stub_mm.cpp:16: ../core/sourcehook/FastDelegate.h:181:2: error: identifier �static_assert� is a keyword in C++11 [-Werror=c++0x-compat] static_assert(sizeof(InputClass)==sizeof(u) && sizeof(InputClass)==sizeof(Outp ^ In file included from ../core/sourcehook/sourcehook.h:118:0, from ../core/ISmmPlugin.h:37, from stub_mm.h:18, from stub_mm.cpp:16: ../core/sourcehook/FastDelegate.h: In function �OutputClass fastdelegate::detail::horrible_cast(InputClass)�: ../core/sourcehook/FastDelegate.h:182:29: error: there are no arguments to �static_assert� that depend on a template parameter, so a declaration of �static_assert� must be available [-fpermissive] "Can't use horrible cast"); ^ ../core/sourcehook/FastDelegate.h:182:29: note: (if you use �-fpermissive�, G++ will accept your code, but allowing the use of an undeclared name is deprecated) ../core/sourcehook/FastDelegate.h: In static member function �static fastdelegate::detail::GenericClass* fastdelegate::detail::SimplifyMemFunc<N>::Convert(X*, XFuncType, GenericMemFuncType&)�: ../core/sourcehook/FastDelegate.h:297:82: error: there are no arguments to �static_assert� that depend on a template parameter, so a declaration of �static_assert� must be available [-fpermissive] atic_assert(N >= 100, "Unsupported memeber function pointer on this compiler")
Code:
../core/sourcehook/FastDelegate.h:799:16: error: �static_assert� was not declared in this scope static_assert(sizeof(UnvoidStaticFuncPtr)==sizeof(this), "Can't use evil meth
Anyone have any ideas why this would happen? I thought static_assert is a part of c++1X, why would it give me errors that its not declared in the scope.
I have tried using GCC4.1, GCC4.8 and GCC5.2.
Any ideas?