Error: No member named 'trunc' in namespace 'std'

I have just included <random> in my code and I am getting error

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__random/poisson_distribution.h:145:23 No member named 'trunc' in namespace 'std'

#include &lt;cmath>
#include &lt;iostream>
#include &lt;random>

using namespace std;
int main() {

    std::cout &lt;&lt; "Hello I am "  &lt;&lt; __cplusplus &lt;&lt; std::endl;
    return 0;
}

Replies

How are you testing this? I put the code you posted into a new Xcode project — created from the macOS > Command Line Tool template, selecting C++ as the language — and it builds and runs just fine:

Hello I am 202002

This is using Xcode 14.3 on macOS 13.3.1.

If you’re not using Xcode, I recommend the test procedure described in this post. That’ll tell you whether your command-line tool setup is working in general.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Same I have done , used "Command Line Tool template, selecting C++ as the language". When I don't include random I get output "Hello I am 201703".

Mac OS - 13.3 Xcode - 14.3

I also selected C++ Language Dialect in build setting as "C++17".

Apparently this works when I run from command line. Following is my Makefile. But I need to debug code so I thought to build in xcode and getting error when I include random.

CXX = clang++
CXXFLAGS = -std=c++17
INCLUDES = -I&#x2F;opt&#x2F;homebrew&#x2F;Cellar&#x2F;boost&#x2F;1.81.0_1&#x2F;include
LIBS = -L&#x2F;opt&#x2F;homebrew&#x2F;Cellar&#x2F;boost&#x2F;1.81.0_1&#x2F;lib -lboost_graph
SRC = main.cpp
EXECUTABLE = main

all: $(EXECUTABLE)

$(EXECUTABLE): $(SRC)
	@echo "Compiling ..."
	@$(CXX) $(CXXFLAGS) $(INCLUDES) $&lt; -o $@ $(LIBS) 2>&amp;1 | tee compile.log

.PHONY: clean
clean:
	@echo "Cleaning ....."
	rm -f $(EXECUTABLE)
	@echo "Cleanup Complete. "


run:
	@echo "Running ....."
	@.&#x2F;$(EXECUTABLE) 2>&amp;1 | tee run.log
	@echo "Execution Complete. "

play:
	@echo "Displaying graph"
	@open erdos_renyi.png

build: clean main run

Apparently this works when I run from command line.

Interesting. Most folks who report problems like this and seeing the reverse, where Xcode works but the command line fails.

I also selected C++ Language Dialect in build setting as "C++17".

Did that change the behaviour? Do you still see the failure when you leave that at its default value?

FYI, it didn’t change things for me. My new command-line tool project works either way.

Try this:

  1. Create a new user account.

  2. Log in as that user.

  3. Run Xcode from there.

  4. Create a new test project.

  5. Try to reproduce the problem with that.

What do you see?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"