I'm currently working on a project which executes correctly using an arduino library (VirtualWire), yet would like to move away from Arduino and back into pure C/C++.
I could:
- rewrite the actual arduino functions
- rewrite the calls to arduino functions (change pinmode to DDRx, etc)
- use the arduino core source code in conjunction with the library.
I have already attempted the last point, moving the relevent arduino source code in with the virtual wire library, however when i try to compile- i cant link against the VirtualWire library.
NOTE: the VirtualWire library and its dependencies (hopefully) is located in the same directory as my source code (as a test).
Using the following compile command, i achieve the following errors:
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL -IVirtualWire -LVirtualWire -lVirtualWire transmitter.cpp -o transmitter.o
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: cannot find -lVirtualWire
Or alternatively,
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL -IVirtualWire -LVirtualWire transmitter.cpp -o transmitter.o
C:\cygwin\tmp/cc8d5ab7.o: In function `setup':
transmitter.cpp:(.text+0xe): undefined reference to `vw_set_tx_pin'
transmitter.cpp:(.text+0x14): undefined reference to `vw_set_rx_pin'
transmitter.cpp:(.text+0x1a): undefined reference to `vw_set_ptt_pin'
transmitter.cpp:(.text+0x20): undefined reference to `vw_set_ptt_inverted'
transmitter.cpp:(.text+0x28): undefined reference to `vw_setup'
C:\cygwin\tmp/cc8d5ab7.o: In function `main':
transmitter.cpp:(.text+0x6e): undefined reference to `vw_send'
transmitter.cpp:(.text+0x72): undefined reference to `vw_wait_tx'
transmitter.cpp:(.text+0x80): undefined reference to `delay'
And lastly,
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL transmitter.cpp -o transmitter.o
transmitter.cpp:1:25: error: VirtualWire.h: No such file or directory
transmitter.cpp: In function 'int main()':
transmitter.cpp:26: error: 'HIGH' was not declared in this scope
transmitter.cpp:26: error: 'digitalWrite' was not declared in this scope
transmitter.cpp:27: error: 'uint8_t' was not declared in this scope
transmitter.cpp:27: error: expected primary-expression before ')' token
transmitter.cpp:27: error: 'vw_send' was not declared in this scope
transmitter.cpp:28: error: 'vw_wait_tx' was not declared in this scope
transmitter.cpp:29: error: 'LOW' was not declared in this scope
transmitter.cpp:30: error: 'delay' was not declared in this scope
transmitter.cpp: In function 'void setup()':
transmitter.cpp:42: error: 'CLKPR' was not declared in this scope
transmitter.cpp:44: error: 'vw_set_tx_pin' was not declared in this scope
transmitter.cpp:45: error: 'vw_set_rx_pin' was not declared in this scope
transmitter.cpp:46: error: 'vw_set_ptt_pin' was not declared in this scope
transmitter.cpp:47: error: 'vw_set_ptt_inverted' was not declared in this scope
transmitter.cpp:48: error: 'vw_setup' was not declared in this scope
transmitter.cpp:49: error: 'OUTPUT' was not declared in this scope
transmitter.cpp:49: error: 'pinMode' was not declared in this scope
I am familiar with C/C++, however only today did i find out there were different types of libraries.
Is there something obvious i am doing wrong, or an easier way to transfer this library from Arduino to pure C/C++?
Thanks in advance!
Related
I am learning about OpenGL and am having great difficulty opening a file with openGL. This is what my reference says to do:
"Compile and run the program
To compile the sample program, you need to link to the OpenGL and freeglut libraries. You will also need the GLEW library to be able to use many OpenGL functions, including shaders.
The exact names of these libraries vary from system to system, for example:
Linux
: libGL.a, libglut.a
Compile with
g++ main.cpp -lGL -lglut -lGLE"
I have run this code in my linux terminal (I'm using Redhat) and I get a whole bunch of errors about not being able to locate the files
[a1649446#ingb24w027 code]$ g++ main.cpp -lGL -lglut -lGLEW
main.cpp:46:23: error: glm/glm.hpp: No such file or directory
main.cpp:47:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
main.cpp:48:32: error: glm/gtc/type_ptr.hpp: No such file or directory
main.cpp:62: error: ‘glm’ has not been declared
main.cpp:62: error: expected constructor, destructor, or type conversion before ‘cameraMatrix’
main.cpp: In function ‘int setShaderData(const unsigned int&)’:
main.cpp:102: error: ‘glm’ has not been declared
main.cpp:102: error: expected ‘;’ before ‘projection’
main.cpp:105: error: ‘glm’ has not been declared
main.cpp:105: error: ‘projection’ was not declared in this scope
main.cpp:109: error: ‘glm’ has not been declared
main.cpp:109: error: expected ‘;’ before ‘modelview’
main.cpp: In function ‘void render()’:
main.cpp:187: error: ‘cameraMatrix’ was not declared in this scope
main.cpp:187: error: ‘glm’ has not been declared
main.cpp:200: error: ‘glm’ has not been declared
I'm sure the answer is painfully obvious, but I am an OpenGL noob. I have even located all the openGL libraries and copy-pasted them into the folder with my main.cpp and all associated files, to no avail.
This question already has answers here:
'glCreateShader' was not declared in this scope?
(3 answers)
Closed 8 years ago.
When I try compiling the opengl Code written in c language with gcc with the following commands it runs fine :
gcc -Wall tutorial10.c -lGL -lglut -lGLU
But when I try doing the same compiling it by using g++
g++ -Wall tutorial10.c -lGL -lglut -lGLU
It starts to give a lot of errors like this :
tutorial10.c: In function ‘void drawRect()’:
tutorial10.c:28:34: error: ‘glClearBufferfv’ was not declared in this scope
tutorial10.c:34:28: error: ‘glUseProgram’ was not declared in this scope
tutorial10.c:36:24: error: ‘glGenBuffers’ was not declared in this scope
tutorial10.c:37:37: error: ‘glBindBuffer’ was not declared in this scope
tutorial10.c:47:71: error: ‘glBufferData’ was not declared in this scope
tutorial10.c:49:52: error: ‘glVertexAttribPointer’ was not declared in this scope
tutorial10.c:50:29: error: ‘glEnableVertexAttribArray’ was not declared in this scope
tutorial10.c:52:60: error: ‘glGetUniformLocation’ was not declared in this scope
tutorial10.c:54:42: error: ‘glUniform4f’ was not declared in this scope
tutorial10.c:59:30: error: ‘glDisableVertexAttribArray’ was not declared in this scope
tutorial10.c: In function ‘int main(int, char**)’:
tutorial10.c:93:34: error: ‘glCreateProgram’ was not declared in this scope
tutorial10.c:95:54: error: ‘glCreateShader’ was not declared in this scope
tutorial10.c:124:76: error: ‘glShaderSource’ was not declared in this scope
tutorial10.c:128:36: error: ‘glCompileShader’ was not declared in this scope
tutorial10.c:134:49: error: ‘glAttachShader’ was not declared in this scope
tutorial10.c:136:29: error: ‘glLinkProgram’ was not declared in this scope
tutorial10.c:147:35: error: ‘glDeleteShader’ was not declared in this scope
Headers from comment:
#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
You don't have opengl functions declarations within your translation unit (most likely, you haven't included <GL/gl.h>).
gcc takes that because older versions of C language allows implicit declarations - whenever you use function, gcc automatically declares it with generic rules. It does NOT mean functions will be called properly - implicit rules are very generic and will cause problems on e.g. float argument types, so expect a lot of bugs here.
You can see warnings about implicit declarations if you add -Wimplicit-function-declaration (or -Wall, which includes this, along with many others) to your cflags.
g++, on other side, enabled C++ mode, which forbids implicit declarations.
To sum it all, don't use implicit declarations unless you truly understand what they do (but in that case you wouldn't want to use them anyway).
I am trying to run the sample code shown here. I built wxWidgets from source using MinGW, with this command: mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=debug. In my Eclipse settings, I add -Iwx288/include, -Lwx288/lib, -lwxbase28d_gcc_custom and -lwxmsw28d_core_gcc_custom. I get very very confused, due to the number of ways to compile and inexperience with linkers. I get these errors, what am I doing wrong? I'm not even citing wxMutex in my program.
23:15:19 **** Incremental Build of configuration Debug for project A ****
Info: Internal Builder is used for build
g++ "-IC:\\Files\\Programming\\C++\\A\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "include\\wx\\thrimpl.o" "..\\include\\wx\\thrimpl.cpp"
..\include\wx\thrimpl.cpp:18:1: error: 'wxMutex' does not name a type
..\include\wx\thrimpl.cpp:29:1: error: 'wxMutex' does not name a type
..\include\wx\thrimpl.cpp:34:6: error: 'wxMutex' has not been declared
..\include\wx\thrimpl.cpp:34:22: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:36:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:36:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:39:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:47:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:55:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:224:1: error: 'wxCondition' does not name a type
..\include\wx\thrimpl.cpp:235:1: error: 'wxCondition' does not name a type
..\include\wx\thrimpl.cpp:240:6: error: 'wxCondition' has not been declared
..\include\wx\thrimpl.cpp:240:26: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:240:6: error: redefinition of 'bool IsOk()'
..\include\wx\thrimpl.cpp:34:6: error: 'bool IsOk()' previously defined here
..\include\wx\thrimpl.cpp:242:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:242:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:245:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:253:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:261:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:269:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:281:1: error: 'wxSemaphore' does not name a type
..\include\wx\thrimpl.cpp:291:1: error: 'wxSemaphore' does not name a type
..\include\wx\thrimpl.cpp:296:6: error: 'wxSemaphore' has not been declared
..\include\wx\thrimpl.cpp:296:26: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:296:6: error: redefinition of 'bool IsOk()'
..\include\wx\thrimpl.cpp:34:6: error: 'bool IsOk()' previously defined here
..\include\wx\thrimpl.cpp:298:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:298:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:301:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:309:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:317:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:325:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:299:1: warning: control reaches end of non-void function [-Wreturn-type]
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:243:1: warning: control reaches end of non-void function [-Wreturn-type]
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
23:15:20 Build Finished (took 657ms)
Why are you trying to compile include/wx/thrimpl.cpp? It's not your file, it's part of wxWidgets and it shouldn't be compiled as part of your project. Just remove it from the list of project files.
I'm guessing you are either missing something in your include path or some of the Defines required by wxWidgets in order to process wxWidgets Header-Files correctly
WX comes with a tool called wx-config ( should be located somewhere in wxWidgets/bin if your build was successful)
wx-config is a shell-script, you can execute it using mingw-msys
wx-config --cxxflags produces all Include Paths and Defines needed to compile object files.
wx-config --libs takes care of everything needed to link the program
I would recommend using wx-config in your makefile/builder/....
or check the output produced by it and compare it to your build process
Samples form my current installation:
$ wx-config --cxxflags --static=no --debug=yes --unicode=no -I/wx/lib/wx/include/msw-ansi-debug-2.8 -I/wx/include/wx-2.8 -D_WXDEBUG_ -DWXUSINGDLL -D_WXMSW_ -mthreads
$ ./wx-config --libs --static=no --debug=yes --unicode=no -L/wx/lib -mthreads -Wl,--subsystem,windows -mwindows -lwx_mswd_richtext-2.8 -lwx_mswd_aui-2.8 -lwx_mswd_xrc-2.8 -lwx_mswd_qa-2.8 -lwx_mswd_html-2.8 -lwx_mswd_adv-2.8 -lwx_mswd_core-2.8 -lwx_based_xml-2.8 -lwx_based_net-2.8 -lwx_based-2.8
I get the following error when compiling this third-party library (called azove 2.0) which relies on the GNU Multi-precision library:
> make
g++ -Wall -O3 -DFIX_NUMBER_OF_SIGMDDNODE_SONS -DUSE_TIMER -I. -c conBDD.cpp -o conBDD.o
In file included from conBDDnode.hpp:27,
from conBDD.hpp:25,
from conBDD.cpp:22:
/usr/include/gmpxx.h: In destructor ‘__gmp_alloc_cstring::~__gmp_alloc_cstring()’:
/usr/include/gmpxx.h:2096: error: ‘strlen’ was not declared in this scope
conBDD.cpp: In member function ‘void conBDD::build()’:
conBDD.cpp:61: error: ‘numeric_limits’ was not declared in this scope
conBDD.cpp:61: error: expected primary-expression before ‘int’
conBDD.cpp:61: error: expected `;' before ‘int’
conBDD.cpp:68: error: expected primary-expression before ‘int’
conBDD.cpp:68: error: expected `;' before ‘int’
make: *** [conBDD.o] Error 1
I have tried adding either and both of the following lines
#include <cstdlib>
using std::strlen;
to conBDD.cpp, but the error persists.
I can't tell if this is an error comes from GNU's Multi-precision library or from Azove. Any pointers would be greatly appreciated.
I would start by apportioning blame. Create an empty cpp file, say test.cpp, in your project and include only the offending gmpxx.h file. If you can compile test cpp, GMP is off the hook. Then try including only the offending azove header. If you can compile the azove header in an otherwise empty file, azove is off the hook and something you are including/defining is interfering with them. Once you have narrowed down the source of the problem you should find it easier to fix.
So I am trying to compile the libssh2 library on linux, but when I try to compile the
example it comes up with a lot of errors, and even though I include the headerfile it asks for, it still asks for it.
Here are the error messages and the resulting messages:
~/ gcc -include /home/Roosevelt/libssh2-1.2.5/src/libssh2_config.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c
/home/Roosevelt/libssh2-1.2.5/example/scp.c:7:28: error: libssh2_config.h: No such file or directory
/home/Roosevelt/libssh2-1.2.5/example/scp.c: In function 'main':
/home/Roosevelt/libssh2-1.2.5/example/scp.c:39: error: storage size of 'sin' isn't known
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'AF_INET' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: (Each undeclared identifier is reported only once
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: for each function it appears in.)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'SOCK_STREAM' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:87: error: invalid application of 'sizeof' to incomplete type 'struct sockaddr_in'
Here is the new errors:
scp.c:(.text+0x106): undefined reference to `libssh2_init'
scp.c:(.text+0x1fe): undefined reference to `libssh2_session_init_ex'
scp.c:(.text+0x234): undefined reference to `libssh2_session_startup'
scp.c:(.text+0x288): undefined reference to `libssh2_hostkey_hash'
scp.c:(.text+0x36f): undefined reference to `libssh2_userauth_password_ex'
scp.c:(.text+0x3e7): undefined reference to `libssh2_userauth_publickey_fromfile_ex'
scp.c:(.text+0x437): undefined reference to `libssh2_scp_recv'
scp.c:(.text+0x531): undefined reference to `libssh2_channel_read_ex'
scp.c:(.text+0x5f8): undefined reference to `libssh2_channel_free'
scp.c:(.text+0x628): undefined reference to `libssh2_session_disconnect_ex'
scp.c:(.text+0x636): undefined reference to `libssh2_session_free'
scp.c:(.text+0x66e): undefined reference to `libssh2_exit'
collect2: ld returned 1 exit status
The header file is not included: libssh2_config.h
There is an inclusion directive in the source code, so you have to indicate the path to the header with the -I option: gcc -I/home/Roosevelt/libssh2-1.2.5/src
The -include option shall be used to include a header file which is not explicitly included in the source code with a #include directive.
I just cloned the current git build and went into the 1.2.5 relase but I'm unable to reproduce your problem.
./buildconf
./configure
make
works fine. What are you trying to do exactly?