User forums > Using Code::Blocks
Problems building C++ code using a Serial library
PaulUK:
Dear All,
First post here. I'm quite new to CodeBlocks and working on a wxWidgets based GUI that uses serial coms to talk to an external device.
I got the program to work (using Windows 7) when using CreateFile to setup the serial port. Now I'd like to use a library found here:
https://www.codeproject.com/Articles/992/Serial-library-for-C
I put the serial.cpp and serial.h files in the project folder but when I go to build, I get the following error.
undefined reference to 'CSerial::Open(......)
This is the function that is supposed to open a serial port. Has anyone else had issues with this library in CodeBlocks? It was initially used with MS VS circa 2003. I have included serial.h at the top of the main program file. Thank you.
BlueHazzard:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
stahta01:
--- Quote from: PaulUK on June 16, 2020, 04:28:44 pm ---I put the serial.cpp and serial.h files in the project folder but when I go to build, I get the following error.
--- End quote ---
Did you add serial.cpp to the CB project? If not, try doing so.
If you do not wish to add serial.cpp to the CB project; then, you need to build the library and link to it.
Tim S.
PaulUK:
--- Quote from: stahta01 on June 16, 2020, 05:05:00 pm ---
--- Quote from: PaulUK on June 16, 2020, 04:28:44 pm ---I put the serial.cpp and serial.h files in the project folder but when I go to build, I get the following error.
--- End quote ---
Did you add serial.cpp to the CB project? If not, try doing so.
If you do not wish to add serial.cpp to the CB project; then, you need to build the library and link to it.
Tim S.
--- End quote ---
Hello Tim,
Yes, I added the serial.cpp and .h files to the project and they appear in the sources and headers tree.
PaulUK:
I am running Code::Blocks version 20.03 on Windows 7. The compiler I use is GCC default (don't know which version number).
Hope this helps.
Build log:
--- Code: ----------------- Build: Debug in AOR8600 (compiler: GNU GCC Compiler)---------------
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -Wall -g -IC:\SDK\wx313CB\include -IC:\SDK\wx313CB\lib\gcc_lib\mswu -c C:\Users\X\Documents\MyCodeBlocks\AOR8600\AOR8600Main.cpp -o obj\Debug\AOR8600Main.o
g++.exe -LC:\SDK\wx313CB\lib\gcc_lib -o bin\Debug\AOR8600.exe obj\Debug\AOR8600App.o obj\Debug\AOR8600Main.o obj\Debug\portsEnum.o obj\Debug\Serial.o obj\Debug\resource.res -mthreads -static -lwxmsw31u -lwxpng -lwxjpeg -lwxtiff -lwxzlib -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -lshlwapi -lversion -loleacc -luxtheme -mwindows
C:\Users\X\Documents\MyCodeBlocks\AOR8600\AOR8600Main.cpp: In member function 'void AOR8600Frame::OnRecTimer(wxTimerEvent&)':
C:\Users\X\Documents\MyCodeBlocks\AOR8600\AOR8600Main.cpp:177:11: warning: unused variable 'n' [-Wunused-variable]
DWORD n=0;
^
obj\Debug\AOR8600Main.o: In function `AOR8600Frame::OnconnectButtonClick(wxCommandEvent&)':
C:/Users/X/Documents/MyCodeBlocks/AOR8600/AOR8600Main.cpp:201: undefined reference to `CSerial::Open(wchar_t const*, unsigned long, unsigned long, bool)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 10 second(s))
2 error(s), 1 warning(s) (0 minute(s), 10 second(s))
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version