I'm merging from the regular WiFiManager lib to the ESPAsync_WiFiManager by khoih-prog.
Github
However this gives me some Linking Issues. As provided in the Readme I used ESPAsync_WiFiManager.hpp instead of the regular .h.
This resolves most linking errors, however some remain unresolved:
Linking .pio\build\nodemcu\firmware.elf
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\lib244\libAlkomat.a(wifi.cpp.o):(.text._ZN14WiFiManagement8initWifiEv+0x8): undefined reference to `_ZN20ESPAsync_WiFiManagerC1EP14AsyncWebServerP9DNSServerPKc'
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\lib244\libAlkomat.a(wifi.cpp.o):(.text._ZN14WiFiManagement8initWifiEv+0xc): undefined reference to `_ZN20ESPAsync_WiFiManager11autoConnectEPKcS1_'
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\lib244\libAlkomat.a(wifi.cpp.o):(.text._ZN14WiFiManagement8initWifiEv+0x10): undefined reference to `_ZN20ESPAsync_WiFiManagerD1Ev'
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\lib244\libAlkomat.a(wifi.cpp.o): in function `_ZN14WiFiManagement8initWifiEv':
wifi.cpp:(.text._ZN14WiFiManagement8initWifiEv+0x3e): undefined reference to `_ZN20ESPAsync_WiFiManagerC1EP14AsyncWebServerP9DNSServerPKc'
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: wifi.cpp:(.text._ZN14WiFiManagement8initWifiEv+0x4b): undefined reference to `_ZN20ESPAsync_WiFiManager11autoConnectEPKcS1_'
c:/users/christopher/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld.exe: wifi.cpp:(.text._ZN14WiFiManagement8initWifiEv+0x53): undefined reference to `_ZN20ESPAsync_WiFiManagerD1Ev'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nodemcu\firmware.elf] Error 1
I think the issue is that I'm using the library in a different File than the main.cpp:
main.cpp:
#include <Arduino.h>
#include "wifi.h"
void setup()
{
Serial.begin(115200);
WiFiManagement::initWifi();
}
void loop()
{
}
wifi.h
#pragma once
#include <ESPAsync_WiFiManager.hpp> //https://github.com/khoih-prog/ESPAsync_WiFiManager
namespace WiFiManagement
{
void initWifi();
}
wifi.cpp
#include "wifi.h"
using namespace WiFiManagement;
void WiFiManagement::initWifi(){
AsyncWebServer _ws(HTTP_PORT);
DNSServer _dnss;
ESPAsync_WiFiManager wifiManager(&_ws, &_dnss);
wifiManager.autoConnect(AP_NAME);
}
In a clean project using the library in the main file, it compiles fine.
What am I doing wrong here?
Edit:
(Standard) PlatformIO build command:
xtensa-lx106-elf-g++ -o .pio\build\nodemcuv2\firmware.elf -T eagle.flash.4m1m.ld -Os -nostdlib -Wl,--no-check-sections -Wl,-static -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -u app_entry -u _printf_float -u _scanf_float -u _DebugExceptionVector -u _DoubleExceptionVector -u _KernelExceptionVector -u _NMIExceptionVector -u _UserExceptionVector .pio\build\nodemcuv2\src\main.cpp.o .pio\build\nodemcuv2\src\network.cpp.o -L.pio\build\nodemcuv2 -L.pio\build\nodemcuv2\ld -LC:\Users\Christopher\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib -LC:\Users\Christopher\.platformio\packages\framework-arduinoespressif8266\tools\sdk\ld -LC:\Users\Christopher\.platformio\packages\framework-arduinoespressif8266\tools\sdk\lib\NONOSDK22x_190703 -Wl,--start-group .pio\build\nodemcuv2\lib622\libESPAsyncTCP.a .pio\build\nodemcuv2\lib77a\libHash.a .pio\build\nodemcuv2\libba0\libESP8266WiFi.a ".pio\build\nodemcuv2\libc45\libESP Async WebServer.a" .pio\build\nodemcuv2\lib220\libDNSServer.a .pio\build\nodemcuv2\libFrameworkArduinoVariant.a .pio\build\nodemcuv2\libFrameworkArduino.a -lhal -lphy -lpp -lnet80211 -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 -lm -lc -lgcc -llwip2-536-feat -lstdc++ -Wl,--end-group
You need to include the implementation h file into wifi.cpp to solve the undefined reference compile error. The hpp is just the definition.
wifi.cpp
#include <ESPAsync_WiFiManager.h> //https://github.com/khoih-prog/ESPAsync_WiFiManager
#include "wifi.h"
using namespace WiFiManagement;
#define HTTP_PORT 80
#define AP_NAME "AP_NAME"
void WiFiManagement::initWifi(){
AsyncWebServer _ws(HTTP_PORT);
DNSServer _dnss;
ESPAsync_WiFiManager wifiManager(&_ws, &_dnss);
wifiManager.autoConnect(AP_NAME);
}
Related
I'm trying to compile a DLIB example: http://dlib.net/image_ex.cpp.html
and I copied it word-for-word:
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------
int main(int argc, char** argv)
{
try
{
// make sure the user entered an argument to this program
if (argc != 2)
{
cout << "error, you have to enter a BMP file as an argument to this program" << endl;
return 1;
}
And I used this command:
g++ dlib1.cpp -o dlib1 -std=c++11 -O3 -I ~/Packages/dlib/ -lpthread -lX11 -ljpeg -lpng -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT
And despite that command working fine months ago: [Can't include the JPEG_SUPPORT headers in a dlib cpp file ] this time, it gave me hundreds of errors:
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x7e): undefined reference to `dlib::png_loader::is_gray() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x94): undefined reference to `dlib::png_loader::is_gray() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0xaa): undefined reference to `dlib::png_loader::is_graya() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0xd0): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x176): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x1ce): undefined reference to `dlib::png_loader::is_graya() const'
What exactly is going wrong here?
Some of the samples need a command line such as ...
g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp
I guess source.cpp is a "library as cpp code" link : dlib compile
I am trying to compile SFML simple code:
#include <iostream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
using namespace std;
int main(int argc, char* argv[])
{
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("127.0.0.1", 6000);
if (status != sf::Socket::Done)
{
// error...
}
return 0;
}
All libs and dependencies are installed:
sudo apt-get install libsfml-dev
sudo apt-get build-dep libsfml
I am using two methods:
g++ -c main.cpp
g++ -o main main.o -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system
g++ -c main.cpp -I/home/x64joxer/SFML-2.4.0/include
g++ -o main main.o -L/home/x64joxer/SFML-2.4.0/lib -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system
But I still have the same problem:
main.o: In function `main':
main.cpp:(.text+0x27): undefined reference to `sf::TcpSocket::TcpSocket()'
main.cpp:(.text+0x38): undefined reference to `sf::IpAddress::IpAddress(char const*)'
main.cpp:(.text+0x54): undefined reference to `sf::TcpSocket::connect(sf::IpAddress const&, unsigned short, sf::Time)'
main.o: In function `sf::TcpSocket::~TcpSocket()':
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x30): undefined reference to `sf::Socket::~Socket()'
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x56): undefined reference to `sf::Socket::~Socket()'
main.o:(.rodata._ZTIN2sf9TcpSocketE[_ZTIN2sf9TcpSocketE]+0x10): undefined reference to `typeinfo for sf::Socket'
collect2: error: ld returned 1 exit status
I read many tutorials and topics at the forum but I still do not know how too fix it.
My system is Kubntu 15.
Can anyone know how to fix it?
You are linking with graphics, system and window but not with network. Did you try adding -lsfml-network ?
I have created a simple C++ application. I can compile it, and it works fine. But now I need to load the library dynamically, and I have added dlfnc.h to my project and added some more code:
#include <iostream>
#include <dlfcn.h>
void *mylib;
int eret;
using namespace std;
int main() {
mylib = dlopen("mylib.so", RTLD_LOCAL | RTLD_LAZY);
eret = dlclose(mylib);
cout << "!!!Hello, World!!!" << endl; // Prints !!!Hello, World!!!
return 0;
}
Compiling:
cd ~/workspace/LinuxGcc/src
g++ LinuxGcc.cpp
And I got a compilation error:
/tmp/ccxTLiGY.o: In function `main':
LinuxGcc.cpp:(.text+0xf): undefined reference to `dlopen'
LinuxGcc.cpp:(.text+0x25): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
dlfcn.h exist in /usr/include/.
Where is the problem?
From dlopen(3):
Link with -ldl.
so
g++ LinuxGcc.cpp -ldl
will be OK.
The solution is very simple. Add the -ldl flag for linking.
In case of the Bazel build system, linkopts = ['-ldl'].
I've built Boost 1.59 for MinGW 4.9.2 32bit as follows:
bootstrap.bat mingw
b2 --prefix=%USERPROFILE%\Code\Libraries\boost toolset=gcc install (these are static libraries)
When trying to compile:
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace std;
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
cout << "Hello World!" << endl;
return 0;
}
With:
g++ -o test -L %USERPROFILE%\Code\Libraries\boost\lib -l boost_system-mgw49-mt-1_59 -I %USERPROFILE%\Code\Libraries\boost\include\boost-1_59 main.cpp
I get this error:
C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x193): undefined reference to `boost::system::generic_category()'
C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x19d): undefined reference to `boost::system::generic_category()'
C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o:main.cpp:(.text+0x1a7): undefined reference to `boost::system::system_category()'
C:/Program Files (x86)/QT/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: C:\Users\Brady\AppData\Local\Temp\ccsbGjrk.o: bad reloc address 0xe in section `.text$_ZN5boost6system14error_categoryD2Ev[__ZN5boost6system14error_categoryD2Ev]'
collect2.exe: error: ld returned 1 exit status
I'm getting this same error across 2 computers. Any help is appreciated!
It's a linker error. You need to link to the Boost System library.
Do this
g++ -o test -L %USERPROFILE%\Code\Libraries\boost\lib -lboost_system -I %USERPROFILE%\Code\Libraries\boost\include\boost-1_59 main.cpp
I moved from Windows to Ubuntu and I wanted to try some C++ programming on Ubuntu. So here is very simple code and very stupid error which I can't resolve:
horse.h
#ifndef _horse_
#define _horse_
class Horse{
int speed;
public:
void saySomething();
};
#endif
horse.cpp
#include "horse.h"
#include <iostream>
using namespace std;
void Horse::saySomething(){
cout << "iiiihaaaaaaa brrrrr."<<endl;
}
and Main.cpp
#include "horse.h"
int main(){
Horse h;
h.saySomething();
}
After I compile (compilation is successful) and run this I get this error message:
/tmp/ccxuDyrd.o: In function `main':
Main.cpp:(.text+0x11): undefined reference to `Horse::saySomething()'
collect2: ld returned 1 exit status
Please help me somehow.
Try
g++ -c main.cpp horse.cpp (to compile)
g++ -o a.out main.o horse.o (to link)
It seems you only compiled your code but did not link the resulting object files. You probably invoked the compiler like this:
g++ main.cpp
You should instead compile every *.cpp file separately and then link each resulting *.o file. And you should do this with a Makefile.
Actually, the basic idea is the same on Windows with MSVC. The compiler produces object files, the linker links them together.