Ошибка strlen was not declared in this scope

I need to install a simulator in my ubuntu. It is written in C++ and when I try to run make, I get this error strlen was not declared in this scope. Any solution to overcome this error?

asked Dec 30, 2010 at 17:38

Vivek's user avatar

VivekVivek

4,50617 gold badges56 silver badges69 bronze badges

2

This should do it :

#include <cstring>

answered Dec 30, 2010 at 17:41

icecrime's user avatar

icecrimeicecrime

74k13 gold badges99 silver badges111 bronze badges

2

#include <cstring>

Your program may also be looking for ::strlen instead of std::strlen. If this is the case, try

using std::strlen;

answered Dec 30, 2010 at 17:43

dan04's user avatar

dan04dan04

87.3k23 gold badges162 silver badges195 bronze badges

did you install all packages you needed?

  1. try g++ —version and see if it gives something.
  2. check /usr/lib/include/ for string.h.

If those things are not there, you need to check if the correct package is installed or not.

answered Dec 30, 2010 at 17:42

Spike's user avatar

SpikeSpike

3022 silver badges4 bronze badges

2

I need to install a simulator in my ubuntu. It is written in C++ and when I try to run make, I get this error strlen was not declared in this scope. Any solution to overcome this error?

asked Dec 30, 2010 at 17:38

Vivek's user avatar

VivekVivek

4,50617 gold badges56 silver badges69 bronze badges

2

This should do it :

#include <cstring>

answered Dec 30, 2010 at 17:41

icecrime's user avatar

icecrimeicecrime

74k13 gold badges99 silver badges111 bronze badges

2

#include <cstring>

Your program may also be looking for ::strlen instead of std::strlen. If this is the case, try

using std::strlen;

answered Dec 30, 2010 at 17:43

dan04's user avatar

dan04dan04

87.3k23 gold badges162 silver badges195 bronze badges

did you install all packages you needed?

  1. try g++ —version and see if it gives something.
  2. check /usr/lib/include/ for string.h.

If those things are not there, you need to check if the correct package is installed or not.

answered Dec 30, 2010 at 17:42

Spike's user avatar

SpikeSpike

3022 silver badges4 bronze badges

2

I am trying to compile several third-party software from source code (i.e. zchaff, argosat) and get errors such as:

Error: ‘strlen’ was not declared in this scope
Error: ‘strcmp’ was not declared in this scope

Here’s the full error message text (also on Ubuntu Pastebin):

erelsgl@erel-biu:~/Dropbox/theorem-prover/argosat-1.0$ make
make  all-recursive
make[1]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0'
Making all in src
make[2]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src'
Making all in strategies
make[3]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src/strategies'
/bin/bash ../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../.. -I../../src -I../../src/auxiliary -I../../src/basic-types   -ffloat-store -Wall -Woverloaded-virtual -ansi -pedantic -Wno-strict-aliasing -DNDEBUG -O3 -MT libstrategies_la-RestartStrategy.lo -MD -MP -MF .deps/libstrategies_la-RestartStrategy.Tpo -c -o libstrategies_la-RestartStrategy.lo `test -f 'RestartStrategy.cpp' || echo './'`RestartStrategy.cpp
 g++ -DHAVE_CONFIG_H -I. -I../.. -I../../src -I../../src/auxiliary -I../../src/basic-types -ffloat-store -Wall -Woverloaded-virtual -ansi -pedantic -Wno-strict-aliasing -DNDEBUG -O3 -MT libstrategies_la-RestartStrategy.lo -MD -MP -MF .deps/libstrategies_la-RestartStrategy.Tpo -c RestartStrategy.cpp -o libstrategies_la-RestartStrategy.o
In file included from ../../src/SolverListener.hpp:22:0,
                 from RestartStrategyConflictCounting.hpp:24,
                 from RestartStrategyMinisat.hpp:22,
                 from RestartStrategy.cpp:22:
../../src/basic-types/Literal.hpp: In static member function ‘static void ArgoSat::Literals::shuffleVector(std::vector<unsigned int>&)’:
../../src/basic-types/Literal.hpp:83:23: error: ‘rand’ was not declared in this scope
RestartStrategy.cpp: In static member function ‘static ArgoSat::RestartStrategy* ArgoSat::RestartStrategy::createFromCmdLine(ArgoSat::Solver&, int, char**, int)’:
RestartStrategy.cpp:33:40: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:35:37: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:37:37: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:39:34: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:41:36: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:43:41: error: ‘strcmp’ was not declared in this scope
make[3]: *** [libstrategies_la-RestartStrategy.lo] Error 1
make[3]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src/strategies'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0'
make: *** [all] Error 2
erelsgl@erel-biu:~/Dropbox/theorem-prover/argosat-1.0$

I found in other questions, such as https://stackoverflow.com/questions/4564850/strlen-was-not-declared-in-this-scope-c, that these errors can be solved by inserting «include» statements into the source code.

But, I downloaded the source code from other sites and I am pretty sure it works for them as is. So, why doesn’t it work for me?

(I have Ubuntu 12.04.4, g++ 4.6.3)

Ответ hoggy конечно точный, и слово «пространный» в моем понимании значит развернутый, подробный, а не краткий, понятный может только профи.

По поводу ошибок в течении цикла издания книги — это врятли, так как, повторяю, что далеко не один исходник ведет себя подобным образом, то есть компилируется в студии и застревает в gcc. Так что по Вашим словам выходит автор создал плохой неперносимый код, который работает в одном компиляторе, но не может в другом. Кроме того, в книге указано, что проверялись исходники :

The book’s examples have all been tested successfully with the
following compilers:

Borland C++, Version 5.5 (DOS/Windows),
Borland C++ Builder 6,
SGI C++, version 7.3.1.1m
GNU C++, version 2.95.2

Резюмируя, чтобы не продолжать на мой взгляд уже чрезмерно обсосаную тему, благодарю всех, кто откликнулся. Причина более или менее понятна, хотя и до конкретного места затыка не добрались, но это дело времени и желания. Предлагаю тему закрыть.

Добавлено через 9 минут
Хотел еще уточнить, а то здесь многие к словам придираются: Причина более или менее понятна, хотя и до конкретного места затыка,

вернее места , где студия обходит затык,

не добрались, но это дело времени и желания.

Arduino Forum

Loading

  • Ошибка string or binary data would be truncated the statement has been terminated
  • Ошибка string cannot be converted to string
  • Ошибка stream read error
  • Ошибка stream not found
  • Ошибка stray 321 in program