Comments (5)
You should also link with Fruit. Just add -lfruit
to your g++ command.
In hindsight, this is probably the same issue that @PedroAreias was reporting, so I've now added a note to the prebuilt packages section of the wiki explaining this.
from fruit.
Thanks for the report. Could you please provide some more info?
- What version of Fruit are you using?
- What commands did you execute to get that error? (cmake then make I guess? With what options?)
from fruit.
I cannot reproduce this issue.
I've tried with the latest version (Fruit 2.0.4) using GCC 5.4.0, building the example either via cmake+make or via a manual compile command.
If you haven't managed to find a solution yet, please let me know what you did to get this issue, without additional information I'm unable to help.
from fruit.
Closing since I am unable to reproduce/fix this without more information. If you can still reproduce please reopen and provide the information asked in the previous comments.
from fruit.
Getting the same error
main.o: In function `fruit::impl::MemoryPool::~MemoryPool()':
/usr/include/fruit/impl/data_structures/memory_pool.defn.h:51: undefined reference to `fruit::impl::MemoryPool::destroy()'
main.o: In function `fruit::impl::SemistaticGraph<fruit::impl::TypeId, fruit::impl::NormalizedBinding>::at(fruit::impl::TypeId)':
/usr/include/fruit/impl/data_structures/semistatic_graph.defn.h:125: undefined reference to `fruit::impl::SemistaticMap<fruit::impl::TypeId, fruit::impl::SemistaticGraphInternalNodeId>::at(fruit::impl::TypeId) const'
main.o: In function `fruit::Injector<Logger>::Injector<>(fruit::Component<Logger> (*)())':
/usr/include/fruit/impl/injector.defn.h:37: undefined reference to `fruit::impl::InjectorStorage::InjectorStorage(fruit::impl::ComponentStorage&&, std::vector<fruit::impl::TypeId, fruit::impl::ArenaAllocator<fruit::impl::TypeId> > const&, fruit::impl::MemoryPool&)'
main.o: In function `std::default_delete<fruit::impl::InjectorStorage>::operator()(fruit::impl::InjectorStorage*) const':
/usr/include/c++/5/bits/unique_ptr.h:76: undefined reference to `fruit::impl::InjectorStorage::~InjectorStorage()'
collect2: error: ld returned 1 exit status
g++ version:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.10' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)
main.cpp
#include <fruit/fruit.h>
#include <iostream>
#include "Logger.h"
int main(int argc, char const *argv[])
{
fruit::Injector<Logger> injector(getLoggerImplComponent);
Logger* logger = injector.get<Logger*>();
logger->Log("Hello");
/* code */
return 0;
}
Logger.h
#include <string>
class Logger {
public:
virtual void Log(const std::string& s) = 0;
};
fruit::Component<Logger> getLoggerImplComponent();
LoggerImpl.cpp
#include <fruit/fruit.h>
#include <iostream>
#include "Logger.h"
class LoggerImpl : public Logger {
public:
INJECT(LoggerImpl()) = default;
virtual void Log(const std::string &s) override {
std::cout << s;
}
};
fruit::Component<Logger> getLoggerImplComponent() {
return fruit::createComponent()
.bind<Logger, LoggerImpl>();
}
$ g++ -std=c++11 -g main.cpp LoggerImpl.cpp
Using Fruit 3.1.1 installed from the apt repo
from fruit.
Related Issues (20)
- Fruit does not build in Visual Studio Versions 2019, 2022 or 2022 Preview with CMake HOT 8
- what should I do to use a string as an annotion of some bind? HOT 3
- VS2022 Just My Code for Fruit Library fails using CMAKE HOT 6
- Create a fruit::Component by iterating over a list of fruit::Components HOT 7
- Can fruit be used with C language? HOT 2
- Handling lifetimes HOT 6
- Providing non-injected arguments to DI Objects HOT 14
- Build fails with Visual Studio 2022 with C++20 HOT 8
- Fruit with QT HOT 4
- Factories with reference types broken in fruit 3.7.0
- Generic binding? HOT 2
- Defining Factory Functions for Objects with Multiple Constructors HOT 11
- Replace boost HOT 1
- Creating Collections of DI Objects HOT 3
- [Suggestion] ExtractFirstError meta function SHOULD be non-error safe HOT 2
- Can no longer build examples in VS2022 Preview built by Visual Studio, VS CMake builds OK HOT 7
- Examples miss virtual dtor
- bindInstance with copy HOT 13
- Understanding Compiler error messages in Fruit HOT 6
- Adding a special constructor to one implementation of an interface HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fruit.